How to Set Up PHP Composer
Last modified: 2025 June 24
Because WebPros International, LLC doesn’t develop or ship PHP Composer, cPanel Technical Support can’t help you set it up.
Overview
Composer is a dependency and package manager for PHP. For more information about Composer, read the Composer documentation. You can search for packages to download at the packagist.org website.
Your cPanel account must possess SSH access in order to use Composer.
How to install Composer
This section only applies to cPanel & WHM version 130 or later. We no longer ship the cpanel-php-composer package. In prior versions, we included it with your installation.
To to install Composer, follow the instructions on the Composer website.
We recommend that you install Composer globally.
How to set up Composer
In order to use Composer, you must install several PHP modules. You must also verify that you have properly configured your server’s php.ini file to allow Composer to run.
By default, when you call Composer, it only uses the server’s php.ini file. The system stores this file in the /opt/cpanel/ea-*/root/etc/php.ini location.
Required PHP modules
You must perform these steps as the root user.
To use Composer, you must enable several PHP modules in EasyApache. For more information about EasyApache 4, read our EasyApache 4 documentation.
-
Phar — This module provides a way to store entire PHP applications into a single “phar” file (PHP Archive) for easy distribution and installation.
Note:EasyApache 4 installs this module by default.
-
Iconv — This module provides a Character Set Conversion.
Note:If you install this module, the
MBstringmodule is not required. -
Mbstring — This module provides enhanced Chinese, Japanese, and other language support.
Note:If you install this module, the
Iconvmodule is not required.
Required PHP directives
You must update the following PHP directives in the php.ini file:
We strongly recommend that you only edit your server’s php.ini files with cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor).
allow_url_fopen—Onzend.detect_unicode—Off
For servers that use PHP version 5.3 and earlier, use the detect_unicode directive instead of the zend.detect_unicode directive.
Servers that use Suhosin
If you use Suhosin, you must add the Phar PHP module to the Suhosin whitelist in the server’s php.ini file. Add the following line to your server’s php.ini file:
suhosin.executor.include.whitelist=pharWe strongly recommend that you only edit your server’s php.ini files with cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor).
What if I cannot edit the php.ini file
If you cannot make changes to the php.ini file, you must manually run the following command each time you run Composer:
- With Suhosin:
php -d allow_url_fopen=1 -d zend.detect_unicode=0 -d suhosin.executor.include.whitelist=phar $(which composer)- Without Suhosin:
php -d allow_url_fopen=1 -d zend.detect_unicode=0 $(which composer)If you use Composer often, you can create a Bash alias to perform this step for you. If you add an alias, you can run the composer command without any additional flags or options. Add the following line to your .bashrc file to create this alias each time that you log in to the server:
- With Suhosin:
alias composer="php -d allow_url_fopen=1 -d zend.detect_unicode=0 -d suhosin.executor.include.whitelist=phar $(which composer)"- Without Suhosin:
alias composer="php -d allow_url_fopen=1 -d zend.detect_unicode=0 $(which composer)"Troubleshoot Composer
Command not found
If you receive a command not found error message, you may need to add the proper path to your account’s .bash_profile file.
cPanel & WHM version 128 and earlier
Add the following line to your account’s .bash_profile file:
source /etc/profile.d/cpanel-php-composer.shIf you experience problems with the source option, add the PATH option to the .bash_profile file instead:
PATH=$PATH:/opt/cpanel/composer/binYou must log in to the server again for any changes to the .bash_profile file to take effect.
cPanel & WHM version 130 and later
If you receive a command not found error message, make certain that you installed Composer.
Add the following line to your account’s PATH option in your .bash_profile file:
PATH=$PATH:/usr/local/bin/composer- This assumes that you installed Composer globally. If you did not, change the
PATHto the location of your installation. - You must log in to the server again for any changes to the
.bash_profilefile to take effect.
The Composer self-diagnostic tool
Composer contains a self-diagnostic tool to ensure that you have properly configured PHP.
Run the diagnostic tool with the following command:
composer diagnoseThe Checking platform setting section provides feedback about your server’s PHP configuration. It will also inform you of any PHP configuration failures.
The following example demonstrates this section:
|
|
Alternative diagnostic tools
If you require an alternate diagnostic tool, use the diagnostic tool from Composer’s Github account. Run the following command:
curl https://raw.githubusercontent.com/composer/getcomposer.org/master/web/installer | php -- --checkThis utility only checks the server’s PHP configuration, as in the following example:
|
|