Question
How do you install composer on cPanel version 130 and higher?
Warning: On cPanel version 130 and up, the Composer package is no longer provided by the base cPanel install. As such, this will need to be installed manually by the server administrator. This package was removed as part of our normal deprecation plan, which can be viewed here:
cPanel's deprecation Plan | cPanel & WHM Documentation
Answer
- Start by verifying that the "allow_url_fopen" PHP variable is enabled for the server's default PHP version. We have steps on enabling this if needed in this article:
Changing the "allow_url_fopen" Setting for PHP - Log in to the server via SSH as the
rootuser -
Download the installer for the composer software:
# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
-
Download the latest composer signature key from the Composer GitHub page, which is used to validate that the installer is valid:
# php -r "copy('https://composer.github.io/installer.sig', 'composer.sig');"
-
With those in place, verify the composer installer is valid. This uses the latest installer signature downloaded as "composer.sig" in the step above. This will either say "Installer verified" or "Installer corrupt":
# php -r "if (hash_file('sha384', 'composer-setup.php') === trim(file_get_contents('composer.sig'))) { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
-
Run the actual installer for composer if it was verified by the previous step:
# php composer-setup.php
-
Move the composer utility into the
/usr/local/bindirectory, so it's within the default Path and accessible to users:# mv -v composer.phar /usr/local/bin/composer
-
Finally, remove the
composer.sigandcomposer-setup.phpfiles created in steps one and two, cleaning up the installation:# php -r "unlink('composer-setup.php'); unlink('composer.sig');"
Performing the steps above will install the composer utility and move the utility into the server's default Path ensuring users can use it. Users on most systems should be able to access and use composer without issues at this stage.
Note: For CloudLinux servers that use CageFS, please see the steps below for adding Composer to the CageFS map.
Additional steps for CloudLinux with CageFS
-
Create the file
composer.cfgwithin the CageFS configuration directory:# touch /etc/cagefs/conf.d/composer.cfg
-
Add the contents below to the file:
CONFIG_TEXT: [composer]
comment=Composer https://getcomposer.org/
paths=/usr/local/bin/composer -
Update CageFS by rebuilding it:
# cagefsctl --force-update
Additional Resources
Changing the "allow_url_fopen" Setting for PHP
How to edit a file on command-line
How to add a command or binary to CageFS for all users using Filesystem Templates
Comments
0 comments
Article is closed for comments.