Composer is a very powerful tool if you create PHP applications, however, installation can be a little tricky for the first try. This guide should hopefully allow you to install composer, within in a quick and timely fashion.

Prerequisites

When you install Composer, there are a few prerequisites that need to be installed. Some of these are to help get Composer, while others will help in the use of it.

sudo apt install curl git unzip

Installing PHP

The version of PHP available will differ as time passes, however, the best way to install the latest version is to first search for what is available to install.

sudo apt list php*-cli

This should provide a list of available PHP cli packages that can be installed. For instance, at the time of writing this php7.2-cli is the latest version. The required PHP packages can be installed with the following command.

sudo apt install php7.2-cli php7.2-mbstring

Install Composer

Download the latest version

The latest version of Composer can be downloaded from the getcomposer website. Using curl this can be downloaded into the home area.

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

Verifying the download

The next step is to verify that file that’s been downloaded, and is the genuine installer for Composer. In addition, the Installer Signature (SHA-384) hash will need to be got. To do so visit the Composer public key github page. Create a variable called HASH with the key. The key below may not be the valid key, and is not advisable to use.

HASH=48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5

The following command will verify the file against the created HASH variable.

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

If the file is authentic the following will be displayed.

Installer verified

If the installer is not verified, re-download and try the steps above again.

Install

Composer can now be installed by running the downloaded PHP file with the install-dir and filename arguments.

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

The installation shouldn’t take too long depending on download speeds. After that, if the installer was successful. The following will displayed.

All settings correct for using Composer
Downloading...

Composer (version 1.8.3) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Once Composer is installed it can be used using the composer command.

 composer

In conclusion, if everything worked as to be expected, the screen will produce the Composer welcome message.


Justin Byrne

Justin Byrne is a self motivated tech enthusiasts. Spending more than half his life dedicated to the tech industry. He built his first computer at the age of 11, and has been building ever since. His interests have changed across the years from system building to web programming and even a dab of software engineering., and just like his interests, his operating system has changed sometimes more then 4 times a year.

0 Comments

Leave a Reply