Composer is a dependency manager for PHP. Composer manages all the dependency requirements in your project. It makes easy to install and update the dependencies. Dependency is some code on which your project code depends to work perfectly. Dependencies are code written by someone and used by other.
Consider you have a PHP application which authenticates users. Here are two ways to accomplish this. You can write all the authentication related code by yourself or use any standard authentication library such as PHP OAuth library. Here OAuth library is the dependency for your project. For this to use, you have to download it from the Internet and put it into your project. Whenever there is an update to the library, you have to manually download it and replace the previous one in your project with it. Occasionally, you have to make some adjustment in your project.
This is just one dependency. What if your project contains tens or twenties of such dependencies? It becomes difficult to manage all the dependencies by yourself. Here comes Composer. It almost automates all these things for you. You just specify which dependency to be included in your project and it does. You just tell it to check for updates. Composer checks for updates and download available updates.
Before you can use composer, you have to install it in your system. So, let’s jump in the installation.
Ensure that you have apache installed. To check run the following command in the terminal.
Your output should look something like following
- Ensure that you have php installed. To check run the following command in the terminal.
- Ensure that you have cli module for php installed. If not installed install it.
For php version 5, run following command to install it.
sudo apt-get install php5-cli
For php version 7, run following command.
sudo apt-get install php7.0-cli
Click here to download the installer file
Rename the file to composer.php
Open a terminal and navigate to the directory containing the installer file. Run the following command to install the composer globally.
sudo php composer.php --install-dir=/usr/local/bin --filename=composer
- Run the command composer to verify whether the composer is installed or not. Your output should look like following