Posted in LINUX PHP & MySQL

How to Install Composer in Ubuntu 20.04 LTS (Focal Fossa)

How to Install Composer in Ubuntu 20.04 LTS (Focal Fossa) Posted on May 11, 2020Leave a comment
I'm Hari Prasad Chaudhary from Nepal, developer of the finest educational website/app "MeroSpark" and the finest eCommerce system "PasalaY". Here I share the code snippet which I learn during development.

Composer is very important for PHP developers to install different packages. You can get all the PHP packages from packagist.org. To install those packages on your project folder, you need Composer installed on your machine.

Install Dependencies:

If you have already installed “curl, php-cli, php-mbstring, git, unzip” then no need to install it again. Otherwise, hit the command mentioned below in your terminal.

sudo apt update
sudo apt install curl php-cli php-mbstring git unzip

This command will install dependencies for composer.

Download and Install Composer:

To download composer installer hit the command below or you can download from its official website.

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

Now you need to verify the installer. To do that, get the latest Composer Public Keys / Checksums for the installer.

Composer Public Keys / Checksums
Copy the green-bordered text.

Get the Green-bordered text from the link above and hit the following command.

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

Replace the string and hit enter and it will return "Installer verified". Now you can go further, hit the command below.

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

After this, you will get the output like below:

composer install output

To test whether the composer command is installed or not, hit the "composer" command on your terminal. To install any package, go to the folder where you want to install the package, and open terminal on that directory and hit command like below:

composer require phpmailer/phpmailer
I'm Hari Prasad Chaudhary from Nepal, developer of the finest educational website/app "MeroSpark" and the finest eCommerce system "PasalaY". Here I share the code snippet which I learn during development.

Leave a Reply

Your email address will not be published. Required fields are marked *