What is Composer ?

By | 1 July, 2016
Share Article

what-is-composer

The Composer or PHP Composer is a dependency management tool for PHP. It is similar to npm in node and bundler in ruby. Composer is a command line tool. Composer is used by almost modern frameworks and CMS.

Composer is used to manage the libraries on which the project depends. Composer use a file named composer.json to read the dependencies. As a developer you need to declare the library name and version required by your application into composer.json file and after that you can use the Composer to install or update the libraries.

The best thing about the composer is that it take care of dependencies of the packages also. For example i want to use a package phpunit, this package depends on symfony/yaml & some more package. So, before using the php unit you need to install Symfony/yaml. What if Symfony/yaml depend on other package and so on.

So, if you need to do it manually then its a time consuming and a hectic job. But if you are using composer then no need to worry about all this. Composer will automatically install all the dependencies of the package for you.

Composer use Packagist as its main repository. Packagist allows to install public PHP packages using Composer. You can also make and publish your packages to Packagist. So, whenever you try to install or update any package using composer, Composer first search that package on Packagist and download that package for you.
Now question is How i will load composer packages to my project ?

It is very simple and don’t need any complex configuration. When you install package using composer. Composer creat a dirctory named Vendor and put all the packages into that library. Composer also create a file vendor/autoload.php. You just need to require this file.

Composer requires PHP 5.3.2+ to work. So you need to install PHP before installing the composer. Make sure PHP is runable via Command Prompt or Terminal.

How to install composer on Windows ?

Installation of composer on windows is very easy. You just need to download and run Composer-Setup.exe. This will install the composer on your machine as well as add composer PATH to your system. So you can directly use composer command in command prompt.

How to install composer on Ubuntu ?

Installation of composer on ubuntu is also easy. You just need to run this command

This command will download and install Composer and add as command to your machine for you. So you can directly use composer command in terminal.

Leave a Reply

Your email address will not be published. Required fields are marked *


*