Installing Composer on cPanel servers

Posted on by David Singer | Updated:
Category: Series | Tags: Composer, PHP
Reading Time: 2 minutes
Note:
Please note that this article is considered legacy documentation because cPanel 58 has reached its end-of-life support.

With a tool like Composer it is generally best to have the ability to run it as any user on the server and from any directory. This is generally referred to as being 'globally installed' as any user can access the tool from any location. In this guide we will detail how to install Composer globally on a cPanel based server.

Pre-Flight Check

  • These instructions are intended specifically for installing Composer on a cPanel based server running WHM prior to version 58.
  • We'll be logging in as root to a Liquid Web Fully Managed cPanel server.
As of WHM version 58 cPanel is now including a version of Composer by default, this can be accessed by simply calling composer from command line.
For more details see: What's New in WHM 58 & What to Look For

Step #1: Get the installer

Acquire the Composer installer script with the following commands:

EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$EXPECTED_SIGNATURE') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

The above commands will: get the installer's signature, get the installer file, verify the download by checking the signature and finally confirm if the installer is valid, or corrupt. You should see output similar to:

Installer verified

Step #2: Run the installer

To run the installer in a manner that will install composer globally run the following command:
php ./composer-setup.php --install-dir=/usr/local/bin --filename=composer

With this command run as root composer should now be globally installed on the server.

Step #3: Verify the install

In order to verify the composer installation was successfully you will want to do the following to test. First, as root, run the following command:
# composer -V

You should see something similar to:

Composer version 1.2.0 2016-07-19 01:28:52

If that checks out, you will then want to verify Composer works for the users as well. To confirm composer is working for the cPanel accounts SSH into your server as a cPanel user and do the same:

$ composer -V

You should see something similar to:

Composer version 1.2.0 2016-07-19 01:28:52
Series Navigation
<< Previous ArticleNext Article >>
Avatar for David Singer

About the Author: David Singer

I am a g33k, Linux blogger, developer, student, and former Tech Writer for Liquidweb.com. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Latest Articles

Blocking IP or whitelisting IP addresses with UFW

Read Article

CentOS Linux 7 end of life migrations

Read Article

Use ChatGPT to diagnose and resolve server issues

Read Article

What is SDDC VMware?

Read Article

Best authentication practices for email senders

Read Article