How To Install PHP Composer on a CentOS 7 VPS or Dedicated Server

How To Install PHP Composer on a CentOS 7 VPS or Dedicated Server


Composer is a robust tool designed to streamline dependency management in PHP. The tool pulls and manages all the dependencies and libraries in one place. It installs and updates the libraries that your projects depend on, and enables you to declare these libraries on a per-project basis. Composer is utilized in virtually all latest PHP platforms and frameworks including Drupal, Magento 2, Symfony, and Laravel.

This tutorial will show you how to install PHP Composer on your CentOS 7 VPS or dedicated server.

Before You Start

For this tutorial to flow seamlessly, you require the following:

  • A fully configured CentOS 7 server

Step1 –
Putting All The Dependencies In Place

Before downloading and installing The Composer ensure that your CentOS 7 server has the required dependencies to aid this process.

First, execute the command below to update the cache for your package manager:

$ sudo yum update

Next, install the following dependencies:

  • Curl: Which will help you download Composer.
  • Php-cli:A dependency used to run and install Composer.
  • php-mbstring: The package that will provide the functions for our library.
  • Git: Which the Composer will use to download project dependencies.
  • Unzip: Which will be used to extract the zipped packages.

To install all these dependencies run the command below:

$ sudo yum install curl php-cli php-mbstring git unzip

That’s all! All the dependencies are successfully installed, the stage is set and it should be easy to install Composer.

Step 2 –
Installing The Composer

Composer comes with an installer which is developed in PHP. Download this installer and authenticate it, before using it to install the Composer itself.

First, execute the command below to change to the home directory:

$cd ~

Then, run the command below to get the Installer.:

$ curl -sS -o composer-setup.php

To authenticate this installer, download a SHA-384 hash on this page, and then copy and store this hash as a CentOS shell variable:

$ HASH=93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8

If have the most recent hash, run the command below to match the installer to this hash:

 $ 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 this installer is authentic, you will get an output similar to the one below:

Installer verified

However, if the installer is not authentic, you will get the following output:

Installer corrupt

In such a case, download the installation command again, then scrutinize the hash to ensure its the latest. Once you are sure the script and the hash are correct, run the verification command again.

When the Installer is validated, run the command below to install PHP Composer globally:

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

The command above will install the PHP Composer in the directory, /usr/local/bin, as a system-wide command called composer. Once the process is completed, you will get the following output:<

All settings correct for using Composer

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

Now, run the command below to test the installation.

$ composer

This will give you an output displaying the version of the Composer, together with command options and their descriptions:

  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ // // // /_/ //_/ (__  )  __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
Composer version 1.7.22018-08-1616:57:12

  command [options] [arguments]

  -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: 1for normal output, 2for more verbose output and 3for debug
. . .

This output indicates that the Composer was flawlessly deployed on the CentOS 7 server.


Congratulation! PHP Composer was successfully installed on a CentOS 7 System. You can now explore further options to learn how to utilize the Composer and leverage the power and reliability of this tool.

Check out these top 3 VPS services:

AU$5.92 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
AU$4.42 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
Liquid Web
AU$7.40 /mo
Starting price
Visit Liquid Web
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
4 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install PHP on Your CentOS 7 Server

This article will provide step-by-step instructions on how to setup PHP (an open
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Install cPanel on a CentOS 7 VPS or Dedicated Server

This article provides step by step instructions on how to install cPanel on a Vi
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

Part One: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

This is Part I of a two-part tutorial explaining how to use the different compon
5 min read
Idan Cohen
Idan Cohen
Marketing Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top