How to Install PHP Composer on Ubuntu 18.04 | 20.04

How to Install PHP Composer on Ubuntu 18.04 20.04

This post shows users and new students that how to Install PHP Composer on Ubuntu 18.04 | 20.04. If your are going to Install PHP Composer on Ubuntu then this post is ideal for you.

PHP Composer is package management tool for the PHP language that provides a dependency management of PHP software and required libraries. It allows you to declare the libraries to your project depends on and it will manage them for you. PHP Composer was developed by Nils Adermann and Jordi Boggiano.

It is maintains a list of required packages in a JSON file that is as called composer.json.

For more detail about PHP composer, go to its official website.

One requirement for install Composer is to have PHP installed… so when you’re ready, follow the steps below to get Composer installed.

Follow below steps to start installing PHP composer on Ubuntu.

Step 1: Install PHP

PHP Composer requires PHP 5.3 or higher version of PHP. So run the below commands for install PHP on Ubuntu.

sudo apt install php

If you wish to install another versions of PHP that is not available in Ubuntu default repositories then run the below commands to install a third party repository which is contains PHP 7.2, 7.3, 7.4 and its higher version.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Now simply run the below commands to install PHP 7.4. If you wish for another one then just change the number value to install 7.2, 7.3 and its higher version.

sudo apt install php7.4

Step 2: Install PHP Composer

Above step is installed PHP in your system, Now run the below commands to install PHP Composer.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

The above commands will download PHP Composer from its download page and install it into the /usr/local/bin directory.

All settings correct for using Composer
Downloading.

Composer (version 1.6.4) successfully installed to: /usr/local/bin/composer

Use it: php /usr/local/bin/composer

Now run the below commands check whether Composer is installed or not.

composer

The output of above command should look similar like below.

 ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.6.4 2018-04-13 12:04:24

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.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

When you want to install a PHP based application that requires Composer, simple reference this page to learn how to install Compser… after that, continue with getting your PHP application on Ubuntu.

PHP Composer also upgraded by running the below commands, this process will upgrade all packages that is associated with PHP Composer.

sudo composer self-update

That’s all

If you find any error and issue in above steps , please use comment box below to report.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top