How to Install PHP Composer on Ubuntu 20.04

How to Install PHP Composer on Ubuntu 20.04

Composer is a package manager for installing and managing the required modules for PHP applications. PHP composer dependency manager is similar to pip for python or npm for Node.js applications. Using the composer tool, you can manage all PHP dependencies and libraries for your project. The required PHP modules can be installed easily in your application with the help of the composer manager. This tool is used in almost all modern PHP frameworks such as Drupal, Laravel, and Magento.

We will give you a demo in this article on how to install PHP Composer on your Linux Ubuntu 20.04 environment.


  • All the PHP required modules should be installed on your system.
  • Users must have sudo privileges to run the terminal commands.

Installation of PHP composer on Ubuntu 20.04

The PHP composer installation will complete into the following steps on your Ubuntu 20.04 system:

Step 1: Install PHP modules

First, make sure that all composer necessary PHP requirements are installed on your system. Access the command line application ‘Terminal’ by using the ‘Ctrl Alt+t’. Now, If PHP is not installed then, just update the apt repository and run the below-mentioned command to install PHP requirements:

$ sudo apt update
$ sudo apt install wget php-cli php-zip unzip

Step 2: Download the Composer setup

Now, download an executable file to install the PHP composer on your system. The following wget command will help you to download the setup file:

$ wget -O composer-setup.php https://getcomposer.org/installer

When the above command is executed, it saves the installer file ‘composer-setup.php’ in the current working directory of your Ubuntu system.

Step 3: install PHP composer 

Php composer can be installed either globally or locally as a part of the project. Here, we have installed the PHP composer globally in this article. To install the PHP composer globally. You need to place the downloaded setup file in the system path ‘/usr/local/bin’ directory. So, using the following command you can install PHP composer globally on your Ubuntu 20.04 system:

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

The following output should show on the terminal after executing the above command:

Once the composer installation is completed on your system. Now, run the composer in the terminal to use the composer environment.

$ composer -v

The above command will show you the installed PHP composer version and all options that will help you to use the composer through the terminal.

Create PHP project using composer

Using the composer, you can create a root directory for php project by running the following command:

$ mkdir ~/test-composer-project
$ cd ~/test-composer-project

Now, if you want to install a PHP module in the above directory then, use the following syntax to install a new PHP module:

$ composer require {php-module-name}

You can also update the composer to a newly available version by running the following command:

$ sudo composer self-update


We have demonstrated in this article how to install PHP Composer on Ubuntu 20.04 system. Moreover, we have a basic overview of how to use the composer to create a new project. Give us your feedback about this article through comments.

Similar Posts