Composer is a PHP dependency manager, similar to npm for node.js or pip for python, and is primarily used by Magento, Drupal, Craft, and other PHP-based CMS.
Downgrading Composer for PHP involves reverting to a previous version of the Composer tool. It may be necessary if you encounter compatibility issues or need to use a specific version for your project.
Downgrading Composer should be done with caution, and it is recommended to thoroughly test your project after the downgrade to ensure it functions as expected with the older Composer version.
This article explains the process of installing a local version of Composer for a cPanel user, and downgrading/upgrading Composer if required.
Downgrade
IMPORTANT: If experiencing an error similar to Your Composer dependencies require a PHP version ">= 8.0.2".
, downgrading composer will not resolve the error as it is the installed dependency that requires the newer PHP version.
- Access your server via SSH using the Terminal in cPanel, located in the Advanced section
- Run the following command to download the Composer installation shell script
wget -qO composer-setup.php https://getcomposer.org/installer
- Use the following wget command to download the expected signature of the latest Composer installer from the Composer's Github page and store it in a variable named HASH
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
- Verify that the installation script is not corrupted by running the following command
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- If the hashes match, the following message will be shown
Installer verified
- If the hashes don't match, the following message will be shown
Installer corrupt
- In this case, you need to re-download the Composer installation script and double-check the value of the $HASH variable with echo $HASH
- Once the installer is verified, continue to Step 5
- In this case, you need to re-download the Composer installation script and double-check the value of the $HASH variable with echo $HASH
- If the hashes match, the following message will be shown
- Run the following command to install Composer locally for a cPanel user
php composer-setup.php --install-dir=/home/userna5 --filename=composer
REPLACE: userna5 with your cPanel username.
NOTE: This will install the local copy of Composer. The next step will change the Composer version in use. - Change the composer version with the following, depending on your needs
/home/userna5/composer self-update --1
REPLACE: userna5 with your cPanel username and --1 with the Composer version desired.
EXAMPLE: To check the version on the local-composer install, a user would run/home/userna5/composer --version
.
EXAMPLE: The previous example would downgrade to version 1. To install Composer version 2.5.3, you would run the following:
/home/userna5/composer self-update 2.5.3
REPLACE: userna5 with your cPanel username. - In order to use the locally installed version, you will need to call it with the following
/home/userna5/composer
REPLACE: userna5 with your cPanel username. - You should receive a success message informing you that the selected version has been installed
Upgrading to version 2.5.3 (stable channel).
Comments
0 comments
Article is closed for comments.