While your reading this article, I assumed that you already has PHP programming language installed. If not yet, you can read it here.
What is Composer?
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Read more about it on their getting started guide.
Why we need Composer?
Again, it is used to declare the libraries your project depends on and it will manage (install/update) them for you. No more manual installation and/or manual updates, composer will do the work. Just a few commands and that's it.
Which OS can run composer?
Linux, Mac, and Windows OS can run composer. Windows is a bit different from my stand of point (because of the exe installer - not really used to it).
Where can I search for packages that I want to install in my project?
You can search or explore at Packagist.org. This is where the packages of composer lives.
How to install composer? (Linux and Mac)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Execute the first line of code to get a copy of composer-setup.php file into your local machine (in your current directory). The second line will check/verify the hash of the file if it matches the original one in their server. The third line is the installer (this will check if your settings are okay to run composer and will download the composer.phar file). And, lastly, the fourth line will remove the installer.
After, running the installer you will have composer.phar file in your current directory. I prefer to rename it to composer and move this file to my /usr/local/bin directory. Or maybe if you want 'root' user to have access on it move it to /usr/bin directory.
If all steps were done properly, you will have no issues. When you try to run composer in your terminal (same as below), you should see a bunch of options.
composer
If you got some error, feel free to comment it.
How to install composer? (Windows)
Just download their exe installer, run it, and will walk you through the process. If you have errors, feel free to comment it.
That's it! You now have composer in your machine! You can now add any PHP dependency packages to your projects.
If you like the article, please leave a thumbs up and subscribe for more! Thanks!