Composer is a widely-used dependency management tool for PHP. It simplifies the process of declaring and managing libraries for your PHP projects. In this tutorial, we will cover the steps to install Composer, update it, and configure it to work with different PHP versions on various control panels like CWP, Vesta, cPanel, and Plesk.
Installing Composer
Step 1: Navigate to the installation directory
Switch to the /usr/local/bin directory to install Composer globally:
cd /usr/local/bin
Step 2: Download Composer
Use the following curl command to download the stable version of Composer:
curl https://getcomposer.org/composer-stable.phar -o composer
Step 3: Set file permissions
Grant execution permissions to the Composer binary to ensure it can be accessed globally:
chmod 755 /usr/local/bin/composer
Step 4: Configure for Ubuntu/Debian
On Ubuntu or Debian systems, create a symbolic link to make Composer accessible from /usr/bin:
ln -s /usr/local/bin/composer /usr/bin/composer
Composer is now successfully installed. You can use the composer command from the shell to manage PHP dependencies.
Verifying Installation
To check the installed Composer version, use the following command:
composer -V
Example output:
[root@server bin]# composer -V Do not run Composer as root/super user! See https://getcomposer.org/root for details Continue as root/super user [yes]? yes Composer version 2.0.7 2020-11-13 17:31:06
Updating Composer
To update Composer to the latest stable version, run:
composer self-update
This command ensures that you are using the most up-to-date version of Composer.
Running Composer with Different PHP Versions
If your server has multiple PHP versions installed, you can specify the desired PHP version by providing its full binary path. For example:
/path/to/php-bin /usr/local/bin/composer install
Composer Commands for Specific Panels
CWP (Control Web Panel)
Using PHP Selector:
/opt/alt/php56/usr/bin/php /usr/local/bin/composer install /opt/alt/php70/usr/bin/php /usr/local/bin/composer install /opt/alt/php71/usr/bin/php /usr/local/bin/composer install /opt/alt/php72/usr/bin/php /usr/local/bin/composer install /opt/alt/php73/usr/bin/php /usr/local/bin/composer install
Using PHP-FPM Selector:
/opt/alt/php-fpm56/usr/bin/php /usr/local/bin/composer install /opt/alt/php-fpm70/usr/bin/php /usr/local/bin/composer install /opt/alt/php-fpm71/usr/bin/php /usr/local/bin/composer install /opt/alt/php-fpm72/usr/bin/php /usr/local/bin/composer install /opt/alt/php-fpm73/usr/bin/php /usr/local/bin/composer install
cPanel/WHM
Use the following commands to run Composer with specific PHP versions:
ea-php71 /usr/local/bin/composer install
ea-php72 /usr/local/bin/composer install
ea-php73 /usr/local/bin/composer install
For other control panels, refer to their official documentation to find the paths to PHP binaries.
Troubleshooting
If you encounter the error:
/usr/bin/env: ‘php’: No such file or directory
This means PHP is not installed in the default location. Specify the full path to the PHP binary to resolve this issue.
That’s It!
Composer is now ready to manage your PHP dependencies efficiently. By following these steps, you can ensure compatibility with various control panels and PHP versions on your server.