How to Install PHP Composer on Ubuntu 20.04

Composer is basically a dependency manager for the programming language, PHP. It functions as some sort of project manager that helps the programmer manage dependencies that will be used on a project to project basis.

Install Dependencies

apt update

apt install wget php-cli php-zip unzip

Output:

root@vps:~# apt install wget php-cli php-zip unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
wget is already the newest version (1.20.3-1ubuntu1).
wget set to manually installed.
The following additional packages will be installed:
    libzip5 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache
    php7.4-readline php7.4-zip

Download and Install Composer

Make sure you’re in your home directory and download the Composer installer using wget.

cd ~

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

Output:

root@vps:~# wget -O composer-setup.php https://getcomposer.org/installer
--2020-10-21 20:38:37--  https://getcomposer.org/installer
Resolving getcomposer.org (getcomposer.org)... 142.44.245.229, 2607:5300:201:2100::4:d105
Connecting to getcomposer.org (getcomposer.org)|142.44.245.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 276190 (270K) [application/octet-stream]
Saving to: ‘composer-setup.php’

composer-setup.php  100%[===================>] 269.72K  1.28MB/s    in 0.2s

2020-10-21 20:38:37 (1.28 MB/s) - ‘composer-setup.php’ saved [276190/276190]

Now, download and install Composer, under /usr/local/bin by running the following command.

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

Output

root@vps:~# php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...

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

To test your installation, run the following command.

composer

Output:

root@crowncloud:~# composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
     ______
    / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                                        /_/
Composer version 1.10.15 2020-10-13 15:59:09

Usage:
    command [options] [arguments]

Options:
    -h, --help                     Display this help message
    -q, --quiet                    Do not output any message
    -V, --version                  Display this application version
            --ansi                     Force ANSI output
            --no-ansi                  Disable ANSI output
    -n, --no-interaction           Do not ask any interactive question
            --profile                  Display timing and memory usage information
            --no-plugins               Whether to disable plugins.
    -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
            --no-cache                 Prevent use of the cache
    -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

This verifies that Composer was successfully installed on your system.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS