composer

What is composer in PHP ?

Posted on Posted in PHP

The composer is a dependency manager for PHP. A composer will manage the dependencies you require on a project by project basis. This means that Composer will pull in all the required libraries, dependencies and manage them all in one place. It came to PHP, most how inspired from managers like NPM (Node package manager).

Now the questions came to mind that why dependencies are project wise? why we can not install the dependent libraries at one place ? The ans is because it might be the case that one project require library with latest version other might not so this is the reason.

Now, lets install composer it can be done by command and by downloading the .exe file that depends on the environment.

ON LINUX :-

$ curl -s https://getcomposer.org/installer | php

$ sudo mv composer.phar /usr/local/bin/composer

ON WINDOWS:-

Download and run the composer-setup.exe (LINK :- https://getcomposer.org/Composer-Setup.exe)

After doing installation it’s time to check

composer -V (Shows the version in “cmd in windows” and “terminal in linux” ).

Now make practical usage of composer in our next project. For that we need to make one composer.json file in our project directory where we define all the dependent library in such a format.

{

'require': {
    'silex/silex': '2.*'
}

}

Then run the “composer install” command in terminal or CMD. You will see that the dependencies loaded within folder named “vendor” in your root directory.