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

Introduction

[openingText]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.[/openingText]

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:

  • [tool]A fully configured CentOS 7 server[/tool]

Step1 –
[stepName]Putting All The Dependencies In Place[/stepName]

[step]

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

[howToDirection]

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

$ sudo yum update

[/howToDirection]

[howToDirection]

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.

[/howToDirection]

[howToDirection]

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.

[/howToDirection]

[/step]

Step 2 –
[stepName]Installing The Composer[/stepName]

[step]

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

[howToDirection]

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

$cd ~

[/howToDirection]

[howToDirection]

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

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

[/howToDirection]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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;"

[/howToDirection]

[howToDirection]

If this installer is authentic, you will get an output similar to the one below:

Installer verified

[/howToDirection]

[howToDirection]

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

Installer corrupt

[/howToDirection]

[howToDirection]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.[/howToDirection]

[howToDirection]

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

[/howToDirection]

[howToDirection]

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
Downloading...

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

[/howToDirection]

[howToDirection]

Now, run the command below to test the installation.

$ composer

[/howToDirection]

[howToDirection]

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

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

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

[/howToDirection]

[/step]

Conclusion

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:

Hostinger
NZ$2.71 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.9
  • Support
    4.9
  • Features
    4.8
  • Reliability
    4.7
  • Pricing
    4.5
Kamatera
NZ$6.82 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hosting.com
NZ$5.10 /mo
Starting price
Visit Hosting.com
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0

How to Install PHP on Your CentOS 7 Server

This article will provide step-by-step instructions on how to setup PHP (an open
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Edit PHP Settings in Apache on an Ubuntu 18.04 VPS or Dedicated Server

This is a detailed guide on editing and configuring most PHP settings running on
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

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
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO
Click to go to the top of the page
Go To Top
HostAdvice.com 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.