install-and-use-composer-on-centos7

How to Install and Use PHP Composer on CentOS 7 (Webuzo)

A composer is an application for tracking the dependencies of a project. It pulls in all the required PHP packages your project depends on and manages them for you.

Instead of replacing system package managers (like apt or yum), Composer allows you to specify a set of libraries for a specific project. With the libraries established, Composer then identifies the versions and dependencies and installs them to the corresponding project.

In this article, learn how to install and use Composer on Webuzo CentOS 7.

Prerequisites

  • A CentOS Linux system
  • PHP 5.3.2 or later installed
  • A user account with sudo privileges
  • Access to a command line/terminal window (Ctrl+Alt+F2)

Steps For Installing PHP Composer on Webuzo CentOS 7

Step 1: Update Local Repository

Before you download and install anything on your system, make sure always to update the local repository:

sudo yum -y update

Step 2: Install Software Dependencies 

If you already have the required dependencies, make sure they are the latest version of the package.

In webuzo you don’t need to install PHP on admin users we will use webuzo installed PHP files.

install supporting software for composer for centos 7

Step 3: Download Composer Installer Script

Next, you’ll need to download the installer script. The following command downloads the file in the directory you’re currently in.

/usr/local/apps/php74/bin/php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');"
download composer installer

Step 4: Verify Integrity of the Download

Once you have the installer script, you’ll need to verify its integrity.

To do so, you need to check whether the SHA-384 hash matches the Installer Signature (SHA-384) found on the official Composer Public Keys page.

Download the authorized signature from Composer’s Github page in the HASH variable:

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

Then, use the following script to compare the official hash against the one you’ve downloaded:

/usr/local/apps/php74/bin/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 two signatures match, the output shows the message: Installer verified.

On the other hand, if the script detects some differences, it displays: Installer corrupt. To solve this issue, you’ll need to re-download the Composer Installer.

Step 5: Install Composer

After verifying the integrity of the file you can move on to installing Composer.

You’ll want to install Composer in the /usr/local/bin directory, as a command accessible from the whole system.

1. To install composer, use the command:

/usr/local/apps/php74/bin/php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Once the installation has been initialized, the following message will appear:

All settings correct for using Composer
Downloading...

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

2. When the installer completes the process, check whether it’s running correctly:

composer

The system should display the running version, along with its syntax and available options :

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.9.0 2019-08-28 11:45:23

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.

3. Finally, delete the installer:

php -r “unlink(‘composer-setup.php’);”

Update Dependencies

If you need to update all the dependencies in your composer.json file you can do so with:

composer update

This command updates dependencies according to the version specified in the file.

You can also update one (or more) dependencies individually:

composer update vendor/package vendor_b/package_b

Conclusion

After reading this guide, you should now know how to set up and configure Composer on CentOS 7 safely. Also, you learned composers basic usage, including creating a PHP project, setting up autoload, and updating dependencies.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Share on tumblr
Tumblr

Leave a Reply

FREE Premium
SSL Certificate

Get premium SSL worth $101 for free:
1. Premium SSL Certificate for unlimited domains 2. 50,000$ Warranty by Sectigo (Comodo) 3. PositiveSSL for your domain for free
  GET MY SSL CERTIFICATE  
close-link
Positive SSL