Getting Started With Composer In PHP

Composer is a tool that allows to manage your third party dependencies in your PHP application, it will allow you to create a list of all third party scripts and libraries and their version number. Composer will then look into the repository of the third party library and the current version number and will automatically download the library into your application

Installing Composer

Composer is bundled as an executable Phar archive, so make sure you have the Phar extension enabled in your php.ini file (uncomment extension=phar.so).

Ultimately as a user, all you have to do is drop a composer.json file in your project and run composer.phar install. This composer.json file defines your project dependencies, and optionally configures composer (more on that later). Here is a minimal example to require one library:

1

2

3

4

5

{

"require":{

"monolog/monolog":"1.0.0"

}

}

You can declare it here (see the last two lines below) and Composer will generate an autoloader for the user that can load all of his project dependencies.