How to Install Composer in CWP/Vesta/Cpanel/Plesk – CentOS/Ubuntu

by Sandeep B.

In this tutorial we’ll install composer quickly and learn how to update composer and use different php version paths with composer, Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Composer can be installed in your server quickly and its very easy to install :-

Installation of Composer

Switch into the /usr/local/bin directory.

cd /usr/local/bin

Download and installing Stable version of Composer by using cURL :

curl https://getcomposer.org/composer-stable.phar -o composer

Fix the permission also this will create global access to composer i.e. user having shell access can execute composer :

chmod 755 /usr/local/bin/composer

That’s it composer is successfully installed.

you can now use composer command in shell to execute.

Check Composer version :

composer -V

Update composer upon new version releases :

to update composer you just need to run this command :

composer self-update

**it will update to stable latest version

Run different php version with the composer :

you need to user the full path for php bin and composer path with the composer sub command we use “install” command here as eg:

/path/to/php-bin /usr/local/bin/composer install

For CWP run composer as php selector and php-fpm selector :

For 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

For 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

For Cpanel/WHM :

ea-php71 /usr/local/bin/composer install
ea-php72 /usr/local/bin/composer install
ea-php73 /usr/local/bin/composer install

For other panel’s multi php refer to the official docs and paths for the php bin file

If this post helps you in any way please consider a donation

Donate with PayPal :

md-donate

Donate with Paytm :

md-donate

You may also like

4 comments

Vasile July 21, 2020 - 4:56 pm

Hi when i run “/opt/alt/php-fpm73/usr/bin/php /usr/local/bin/composer install” on cwp it says there is no composer.json in root directory.

Reply
Sandeep B. July 21, 2020 - 7:24 pm

ensure you’re in correct root dir where composer.json is located for your script.

Reply
Vasile July 22, 2020 - 6:34 am

As you can see in this image when i run composer global about it shows me that composer directory in at “/root/.config/composer” where is also my composer.json file https://i.imgur.com/hUpr8mO.png but i still get that message about composer.json not being in /root

Reply
Sandeep B. July 22, 2020 - 6:44 am

okay I see you need to skip that step since you’re not running different php versions and this steps are only for script installation not for the composer installation.

Reply

Leave a Comment