How to Install PHP Composer on Ubuntu 20.04

If you’ve been coding in PHP for a while, you’re probably aware of how PHP libraries can make your code more reusable and save your time. It used to be more difficult to add libraries to PHP, which resulted in a lot of popular features being reinvented. For instance, A Database Abstraction Layer (DAL) is required for any PHP program, but there was no standard package or library, so many people had to create their own. There were certainly several options available at the time, but it was difficult to put dependencies, monitor them, and maintain your application over time.

Compactly, we need a tool for managing applications and installing libraries, dependencies. This is something Composer excels at. It’s a PHP application-level package manager that has grown in popularity and become the de facto standard for handling PHP application dependencies. It permits users to declare which libraries your project relies on, and it will take care of downloading and upgrading them.

Dependency management:

Composer isn’t the same as Yum or Apt when it comes to package management. Yeah, it handles libraries and packages, but it does so on a project-by-project basis while installing them in a directory, for example, a component inside the project. Drupal does not install something by chance. As a result, it is a dependency manager and also endorses a “national” project through the global command for convenience.

This concept isn’t new, and Composer is strongly influenced by ruby’s bundler and node’s npm.

Let’s assume that

  1. You’re working on a project that relies on many libraries.
  2. Some of those libraries are reliant on others.

System Requirements:

To run Composer, you’ll need PHP 5.3.2 or a higher version. A few delicate compile flags and PHP settings are also needed, but you will be advised about any incompatibilities if you use the installer. Composer is cross-platform, and its developer team worked hard to ensure that it runs smoothly on Windows, Linux, and macOS.

That’s all about PHP composer. Now, let’s start its installation guide on Ubuntu 20.04. Firstly, ensure that you are using the terminal as a ‘superuser’.

Installing PHP Composer on Ubuntu 20.04

Step 1: Open the terminal by pressing ‘CTRL+ALT+T’ or search it manually in the activities and update the packages list.

$ sudo apt update

Step 2: Install the essential requirements for the PHP composer package.

$ sudo apt install php-cli unzip

Step 3: Use the curl command to get the composer set up in your home directory.

$ cd ~
$ curl -sS -o composer-setup.php
$ HASH=`curl -sS`

Step 4: Now, Verify the installer.

$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Step 5: Write-out the following command to install the PHP composer locally.

$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Step 6: Check out the Composer information by utilizing the following command.

$ composer


We have discussed PHP composer, its dependency management, and system requirements. Next, we have shown you a complete procedure of its installation on Ubuntu 20.04.