Composer is a dependency management tool in PHP. For any PHP project you need to use your library of codes. Composer easily manages that task on your behalf helping you to declare those codes. You can also install or update any code in your library through composer. Please visit https://getcomposer.org for more details.
In the opening page of https://getcomposer.org, click the ‘getting started’ link.
In the above page you find two links – ‘locally’ and ‘globally’. It stands for two options. Suppose you don’t want to run composer globally or centrally in your system. In that case, you have to download and install composer each time for every project. But the global option is always preferable because once composer is installed in your system bin folder you can call it any time for any project.
If you are already accustomed with any Linux distribution like Ubuntu you know that for any local PHP project we use to go to ‘/Code/php7book1’ folder. Suppose we are going to build a simple PHP project and we want to name it ‘php7book1’. Open up your Ubuntu terminal (control+alt+t) and first go to that folder first.
To reach there you need to type the following command on your terminal:
Once you’ve reached, you can make a directory here with a simple command:
sudo mkdir php7book1
It will ask for your ‘root’ user password. Type the password and a folder called ‘php7book1’ will be created.
Next in this folder we’ll download and install ‘composer’. Considering you are a beginner, for the sake of brevity I want to download and install composer locally on our Laravel project.
Next issue these two commands – one after another. First you type:
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
It’ll take some time. Next type this:
sudo php composer-setup.php
It’ll organize your composer setup file to go further. Actually your composer is ready to download packages for your coming project. You can test it by creating a ‘composer.json’ file inside your folder. In that ‘composer.json’ file type this:
What does this mean? It means you’re installing ‘monolog’ PHP package for your Laravel project. Will it come to any immediate use? The answer is ‘NO’. We’re actually testing our composer installer and want to see how it works.
Now you can issue the command that will install ‘monolog’ package for you. Type this command on your terminal:
php composer.phar install
It’ll take a little time to install the ‘monolog’ package. It depends on your internet speed.
After the installation is over you’ll find a ‘vendor’ folder and few ‘composer’ files inside your project. Feel free to discover what is inside the ‘vendor’ folder. There you’ll find two folders – ‘composer’ and ‘monolog’. Again you can see what they have inside them. As a beginner it’s an endless journey to discover new things. Try to get acquainted with everything new you have found.
The time has come to install Laravel 5.2 through composer. You can install Laravel just like monolog. It means, you can write that instruction in your ‘composer.json’ file and just update your composer. But as a beginner I recommend to follow the simple-most method.