How to Install PHP Composer on Ubuntu 18.04

r00t July 21, 2018

Install PHP Composer on Ubuntu 18.04

In this tutorial we are going to learn how to install PHP Composer on Ubuntu 18.04. We will also install and configure its prerequisites. The composer is a dependency manager tool for PHP. The basic function of  Composer is to install and update the libraries for your project. Using composer tool we can define required libraries for our project and install with the composer in the single command. We don’t need to search for each library to install.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install PHP Composer on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing PHP on Ubuntu 18.04 LTS.

Composer requires PHP 5.3 or higher, to install PHP on Ubuntu, run the following commands:

sudo apt install php

Step 3. Installing PHP Composer on Ubuntu 18.04 Bionic Beaver.

First, download composer executable and put under bin directory:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

After installation of the complete on your system. Type composer at the command prompt. This will provide you composer version details along with options available with composer command:

composer

Output:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.6.5 2018-07-17 11:17:59

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.

Composer can also be upgraded by running the commands below, this will upgrade all packages associated with Composer:

sudo composer self-update

Congratulation’s! You have successfully install and configure PHP Composer on your Ubuntu 18.04 LTS server. Thanks for using this tutorial for installing PHP Composer on Ubuntu system.

The Tags:

Leave a Comment

Comments are closed.