HomeHOWTOSHow To Install PHP Composer on Ubuntu 22.04|20.04|18.04

How To Install PHP Composer on Ubuntu 22.04|20.04|18.04

Welcome to this guide on how to install PHP Composer on Ubuntu 18.04|20.04|22.04. PHP Composer is a package manager for PHP that allows developers to easily manage and install dependencies for their projects. It simplifies the process of adding third-party libraries and components to PHP projects and helps to ensure that all the required dependencies are installed and compatible with each other.

With Composer, developers can define the required dependencies for their PHP project in a configuration file called “composer.json”. Composer will then automatically download and install the required packages, including any dependencies that the packages themselves require.

Composer also provides a mechanism for updating packages and managing version constraints. Developers can use Composer to update all packages to the latest version or specify specific version constraints to ensure compatibility with their project.

Composer is a widely used and popular tool in the PHP community, and it has helped to streamline the process of managing dependencies and building PHP applications.

Install PHP Composer on Ubuntu 22.04|20.04|18.04

To be able to install and use PHP composer, you need to have PHP installed. To install PHP on Ubuntu 22.04|20.04|18.04 you can follow the aid provided here:

Once installed, you also need to install all the required dependencies:

sudo apt install curl php-cli unzip

Download and Install PHP Composer on Ubuntu 22.04|20.04|18.04

Once the required packages have been installed, download the latest Composer binary as shown:

cd ~ && curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

Once downloaded, you can verify if the installer matches the  SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page.

You can also fetch the keys using the command:

HASH=`curl -sS https://composer.github.io/installer.sig`

Verify if the installer is safe:

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

Now install PHP composer to your PATH using the command:

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

Sample Output:

To test if the PHP composer is running as desired execute:

composer

Sample Output:

Voila!

We have successfully walked through how to install PHP Composer on Ubuntu 22.04|20.04|18.04. I hope this is significant to you.

Read about PHP Composer.

See more:

How to Install PHP 8.2 on Ubuntu 22.04|20.04|18.04

Install LAMP Stack on Ubuntu 20.04

Install MariaDB Database on Rocky Linux 9|AlmaLinux 9

Klinsmann Öteyo
Klinsmann Öteyo
Self proclaimed Geek
- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here