Install composer on Ubuntu (Debian)

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.

  1. Ensure that you have apache installed. To check run the following command in the terminal.

     apache2 -v

    Your output should look something like following


  2. Ensure that you have php installed. To check run the following command in the terminal.
     php -v

    Your output should look something like following composer

  3. 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
  4. Click here to download the installer file

  5. Rename the file to composer.php

  6. 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
  7. Run the command composer to verify whether the composer is installed or not. Your output should look like following composer
This post is licensed under CC BY 4.0 by the author.