When trying to use commands that rely on Composer, such as Drush or Artisan, sometimes the required PHP version of a dependency is higher than the System PHP version, causing the command to fail. The error message is:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.32.
The CLI PHP version can be updated using a symbolic link or symlink as long as the required PHP version is installed on the server.
Related Articles
SSH into Shared Server
SSH into VPS or Dedicated Servers
Update PHP Version via Alias
- SSH into the server
- Determine the PHP version needed by Composer, as stated in the error
EXAMPLE: In the example error message, the required PHP version is PHP 8.0 or higher.Your Composer dependencies require a PHP version ">= 8.0.2".
- Run the following script
setPhpCliVersion() {
echo "Set CLI PHP version to (56,70,71,72,73,74,80,81,82):";
read -r PHPVERSION;
if [[ "${PHPVERSION}" =~ (56|70|71|72|73|74|80|81|82) ]]; then
sed -i -e '/alias php=/d' -e '/alias composer/d' ~/.bashrc;
echo "alias php='/opt/cpanel/ea-php${PHPVERSION}/root/usr/bin/php'" >> ~/.bashrc;
echo "alias composer='php /opt/cpanel/composer/bin/composer'" >> ~/.bashrc;
source ~/.bashrc;
else
echo 'Invalid PHP version';
fi
};
setPhpCliVersion; - Enter the PHP version needed, without the period
EXAMPLE: If needing to use PHP 5.6, enter 56. - Run
php -v
to confirm the correct PHP version is now being applied
EXAMPLE:userna5@domain.com [~]$ php -v PHP 8.0.24 (cli) (built: Oct 4 2022 19:22:22) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.24, Copyright (c) Zend Technologies with Zend OPcache v8.0.24, Copyright (c), by Zend Technologies
Update PHP Version via Symlink
- SSH into the server
- Determine the PHP version needed by Composer, as stated in the error
EXAMPLE: In the example error message, the required PHP version is PHP 8.0 or higher.Your Composer dependencies require a PHP version ">= 8.0.2".
- Symbolically link the correct version of PHP into the perl5/bin folder by running
ln -s /opt/cpanel/ea-php##/root/usr/bin/php ~/perl5/bin/php
REPLACE: ## with the correct PHP version.
EXAMPLE: The following symbolically links PHP 8.0.ln -s /opt/cpanel/ea-php80/root/usr/bin/php ~/perl5/bin/php
- Exit out of SSH completely
- SSH back into the server
- Run
php -v
to confirm the correct PHP version is now being applied
EXAMPLE:userna5@domain.com [~]$ php -v PHP 8.0.24 (cli) (built: Oct 4 2022 19:22:22) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.24, Copyright (c) Zend Technologies with Zend OPcache v8.0.24, Copyright (c), by Zend Technologies
Update PHP Version on All Accounts
IMPORTANT: This solution will require root access. If this needs to be obtained, follow the guide on requesting root access.
CAUTION: The task being performed can only be completed on VPS or dedicated servers.
- Log into Root WHM
- Navigate to MultiPHP Manager, located in the Software section
- Change the PHP Version to the version required
NOTE: This will modify the System PHP version and affect any sites set to "inherit."
TIP: If the necessary PHP version isn't installed, it can be installed in Root WHM.
Comments
0 comments
Article is closed for comments.