How to Install PHP Composer on AlmaLinux 9 or Rocky Linux, Oracle Linux, CentOS, or other RHEL-based Linux distros

PHP Composer installation on Almalinux 9

This guide’s steps are performed on Almalinux 9 but can also be used on Rocky Linux 9, Oracle Linux, CentOS, or other RHEL-based Linux distros.

Step 1: Install the Required Dependencies

A few PHP extensions and tools are required by Composer to work properly. Let’s first install them on our Linux system using the DNF package manager.

sudo dnf install -y php-cli php-zip wget unzip

In the above command, we have installed “php-cli,” which will be required to run PHP commands; “php-zip,” which will handle ZIP archives; “wget,” which will download the Composer installer script; and “unzip,” which will extract files from ZIP archives.

Step 2: Download Composer’s Installer script

After the required tools are on the systems, let’s use “wget” to download the Composer setup script. The command will only fetch the script and do nothing else.

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

Step 3: Install Composer Globally on Almalinux 9

Now that we have the PHP composer installation script, the next thing we do is use the PHP command line to execute the downloaded Composer-setup.php script. The given command will install the Composer globally:

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

In the command, we have used “–install-dir=/usr/local/bin“—this is the directory where we are going to install the Composer, while “–filename=composer” makes the executable accessible as a composer. You can also learn how to Install PHP 7.4 on AlmaLinux 9 or Rocky Linux 9 because the default version of PHP available through the Stream repository on these Linux is PHP 8.x.

Step 4: Test the Installation

As the system is done with the installation, we can verify the Composer by checking its version:

composer --version

or 

composer

 

Update Composer (Optional)

In the future, to install the latest updates for Composer, we can run the “self-update” command as shown here:

composer self-update