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

I recommend download the latest snapshot of the Composer executable directly from the project’s website.

Download Composer into this folder with the following command :

You should see a success message that looks something like this:

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:

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.

Make sure you also check out the official Composer documentation for updates and techniques I couldn’t discuss in this article.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: