How to Install and Use PHP Composer on CentOS 7

Composer is a dependency manager for PHP (similar to npm for Node.js or pip for Python ).

Composer will pull in all the required PHP packages your project depends on and manage them for you. It is used in all modern PHP frameworks and platforms such as Laravel, Symfony, Drupal and Magento 2 .

In this tutorial, we will go through the steps of installing and using Composer on a CentOS 7 machine.

Prerequisites

Ensure that you have met the following prerequisites before continuing with this tutorial:

  • Logged in as a user with sudo privileges
  • Have PHP 7 installed on your CentOS 7 system.

Installing Composer on CentOS

The following steps describe how to install Composer on a CentOS 7 system.

 

  1. First install the PHP CLI (command line interface) package and all other dependencies with:

    # sudo yum install php-cli php-zip wget unzip php-pear php-devel

Once PHP CLI is installed, download the Composer installer script with:

# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  • The command above will download the composer-setup.php file in the current working directory .

  • To verify the data integrity of the script compare the script SHA-384 hash with the latest installer hash found on the Composer Public Keys / Signatures page.

    The following wget command will download the expected signature of the latest Composer installer from the Composer’s Github page and store it in a variable named HASH:

    HASH="$(wget -q -O - https://composer.github.io/installer.sig)"

To verify that the installation script is not corrupted run the following command:

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 the hashes match, the following message will be shown:

Installer verified
  • If the hashes don’t match you will see Installer corrupt. In this case, you need to redownload the Composer installation script and double check the value of the $HASH variable with echo $HASH . Once the installer is verified, you can continue with the next step.

  • Run the following command to install Composer in the /usr/local/bin directory:

    # sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...

Composer (version 1.8.5) successfully installed to: /usr/local/bin/composer
Use it: # php /usr/local/bin/composer
  • The composer is installed as a system-wide command and it will be available for all users.

  • The last step is to verify the installation:

    # composer

The command above will print the Composer’s version, commands, and arguments.

______
/ ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.8.5 2019-04-09 17:46:47

Usage:
    command [options] [arguments]

At this point, you have successfully installed Composer on your CentOS system.

  • composer, install composer on centos 7
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

How to upgrade PHP to 7.4 in centos 7?

Enter the following commands on the terminal to upgrade PHP:      1 . To install the latest...

Protocol Buffer Compiler Installation

How to install the protocol buffer compiler. While not mandatory, gRPC applications often...

How to Install Go on CentOS 7

Go, often referred to as golang is a modern open-source programming language created by Google....

Configure gRPC for go and protoc

Quick start This guide gets you started with gRPC in Go with a simple working example....