How to Set Up PHP Composer
Last modified: February 22, 2024
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 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:EasyApache4 installs this module by default.
-
Iconv — This module provides a Character Set Conversion.
Note:If you install this module, the
MBstring
module is not required. -
Mbstring — This module provides enhanced Chinese, Japanese, and other language support.
Note:If you install this module, the
Iconv
module 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
—On
zend.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=phar
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).
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 the command not found
error message, you may need to add the proper path to your account’s .bash_profile
file.
Add the following lines to your account’s .bash_profile
file:
source /etc/profile.d/cpanel-php-composer.sh
If you experience problems with the source option, add the PATH
option to the .bash_profile
file instead:
PATH=$PATH:/opt/cpanel/composer/bin
You must log in to the server again for any changes to the .bash_profile
file 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 diagnose
The 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 -- --check
This utility only checks the server’s PHP configuration, as in the following example:
|
|