Wednesday, October 9, 2024
Google search engine
HomeGuest BlogsHow To Install PHP Composer on Cpanel

How To Install PHP Composer on Cpanel

In this guide, we will cover the installation of PHP Composer on Cpanel. Composer is a PHP dependency management tool. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Composer doesn’t come pre-installed with PHP or Cpanel and you’ll have to install it manually. Follow our steps below to install PHP Composer on Cpanel.

Step 1: Install required PHP modules in EasyApache

To use Composer, you must enable several PHP modules in EasyApache.

1. Login to your Cpanel WHM dashboard and search for EasyApache

install composer cpanel search easyapache

2. Click on the EasyApache 4 to enable PHP modules

3. Click on the buttonCustomize.

install composer cpanel open easyapache4

4. Navigate to PHP Extensions section

install composer cpanel navigate php

5. Search for extensionsIconv & Mbstring to install.

6. Click on install toggle to enable installation for these extensions

install composer cpanel open search mbstring extension
install composer cpanel search Iconv extension

7.  On the Review Page, click the buttonProvision to install the extensions.

install composer cpanel provision modules

8. If the installation was successful, you should receive the message Provision process finished. Click Done.

Step 2: Set required PHP directives

You must update the following PHP directives in the php.ini file:

Directive Required value
allow_url_fopen On
detect_unicode Off

1. Navigate to WHM > MultiPHP INI Editor > Editor Mode

install composer cpanel open php multi ini editor

2. Edit the INI settings of a PHP version on the dropdown menu. Add the following lines at the end of the php.ini file.

allow_url_fopen = On
detect_unicode = Off

It should look like below

install composer cpanel edit php ini

You must click “Save” to apply the new changes.

Step 3:  Install PHP Composer on Cpanel Server

Now that we have our dependencies set correctly, ssh into your Cpanel Server and download Composer installer:

wget https://getcomposer.org/installer -O composer-installer.php

Run the installer script to deploy Composer globally:

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

You should see output like below:

All settings correct for using Composer
Downloading...

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

You should be able to use composer command

 ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.2.7 2022-02-25 11:12:27

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

To check for the installed version of composer, type the command:

$ composer -V
Composer version 2.2.7 2022-02-25 11:12:27

Here you go!. You now have Composer dependency Manager for PHP installed on your Cpanel Server.

Other Cpanel articles available are:

RELATED ARTICLES

Most Popular

Recent Comments