Install PHP Composer on CentOS 8 - Step by step Process ?

PHP Composer is a dependency manager used for managing all PHP project’s dependencies. It pulls all the needed PHP packages on which a project depends and manages them in a good way.  The composer is used in all modern platforms and PHP frameworks such as Magento 2, Laravel, Drupal, and Symfony. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux Composer queries.

In this context, we shall look into different ways to install PHP composer on your CentOS 8 Linux system.

You can install PHP on CentOS 8 via this guide before completing this installation procedure.


Steps to Install PHP composer on CentOS 8 

By implementing the following steps, we can install PHP composer on CentOS 8 system.


1. Perform system update

First, update all system packages with the below command:

$ sudo apt update


2. Install Required Dependencies

Now, install all necessary dependencies including the PHP command-line interface package on CentOS 8 system by running the following command:

$ sudo dnf install php-cli php-json php-zip wget unzip


3. Download Composer Installer

Once the all above packages are downloaded, download the PHP composer installer script by using the following command:

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

This command will make 'composer-setup.php' file to be downloaded into the current working directory.


4. Verify data integrity

Download the latest composer installer using the following wget command from the Github Composer’s page and store it into a 'Hash' variable:

$ HASH="$(wget -q -O - https://composer.github.io/installer.sig)"

Now, verify that the installation script is either running or not by typing the below-mentioned command on the terminal:

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


5. Install Composer

Here, you will install php composer on your system  by running the below-mentioned command:

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

The above command installs the PHP composer as system-wide and every user can use this command for composer installation.

Now, verify the composer installation by displaying the installed version on the terminal window as follows:

$ composer -V

This will display on the terminal the installed version of composer.


Alternative method: Install PHP composer using a quick way

This method provides the quick method for Composer installation on CentOS 8 system. Perform the following few steps to install PHP composer:


1. Install required PHP, zip, unzip and curl packages by using the following command:

$ sudo dnf install php-cli php-json php-zip curl unzip

2. Using the curl command, download the composer installer:

$ curl -sS https://getcomposer.org/installer |php

3. Now, Move all files of php Composer into the '/usr/local/bin' directory by running the below-mentioned command:

$ sudo mv composer.phar /usr/local/bin/composer


[Need to configure PHP on your Linux system ? We can help you. ]

This article covers the installation procedure of PHP composer on your CentOS 8 system. In fact, Composer is a dependency manager for PHP, it like npm for Node.js or pip to Python. So, it allows you to declare the libraries your project depends on and it will manage (installing/updating) them for you. It is used in all modern PHP frameworks and platforms such as Laravel, Symfony, Drupal, and Magento 2.

Related Posts