Can't use composer due to server reporting wrong PHP version

I have a website setup to use PHP 7.4.

That seems to be working at the application level. But at the server (SSH) level, the PHP version is always reported as v 7.1.33.

This causes a major problem with trying to deploy and manage composer projects. Because the PHP version is detected as being incompatible.

Also, if I do a composer install detects the PHP version as 7.1.33, which is wrong. It’s 7.4.

This results in an error such as this when doing a composer install:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php >=7.3 but your PHP version (7.1.33) does not satisfy that requirement.
  Problem 2
    - Installation request for darkaonline/l5-swagger 6.0.4 -> satisfiable by darkaonline/l5-swagger[6.0.4].
    - darkaonline/l5-swagger 6.0.4 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.

etc.

Or when running other php commands in the project folder, this error is produced:

# php artisan optimize
PHP Fatal error:  Declaration of Symfony\\Component\\Translation\\TranslatorInterface::setLocale($locale) must be compatible with Symfony\\Contracts\\Translation\\LocaleAwareInterface::setLocale(string $locale) in /home/billing.inspiredearth.nz/public_html/vendor/symfony/translation/TranslatorInterface.php on line 24

In LogManager.php line 416:

  Use of undefined constant JSON_INVALID_UTF8_SUBSTITUTE - assumed 'JSON_INVALID_UTF8_SUBSTITUTE'

I am told this is due to the PHP version being wrong.

I see other people have reported this issue going back a few years. What’s the way around it?

How to I get the server to report a php version that’s the same as the website settings?

Another related issue is that there appears to be no way to access the website folders without using root user. But things like Composer shouldn’t be run with the root user. I’ve brought that up in a separate discussion post.

The obvious answer would be to upgrade the default PHP version on your server to 7.4

So there’s nothing within CyberPanel and it’s requirements or approach to configuration, etc., that could be thrown off by that? If that’s the case (and that’s where my uncertainty lies), then yes, an update would do the trick.

In the mean time, I have found that I can change the /usr/bin/php symlink to point to the 7.3 or 7.4 instances of PHP that are already on the server (/usr/local/lsws/lsphp73/bin/php and /usr/local/lsws/lsphp74/bin/php).

That at least got php-cli on a version I require.

Not being able to get around the server on a non-root account is still something I’ve not resolved. I know Composer suggests never running Composer as root. I have no idea what the potential implications are in that scenario.

I am also getting the same error and stuck with PHP V 7.1.33. If you have solved, please kindly share with me. I couldn’t find any solution in the CyberPanel community directory.

Welcome @khunpuie Happy you are here

You can change default PHP version in SSH terminal:

$ cp -f /usr/local/lsws/lsphp74/bin/php /usr/bin/

The default php.ini locations

/usr/local/lsws/lsphp80/etc/php.ini
/usr/local/lsws/lsphp74/etc/php.ini
/usr/local/lsws/lsphp73/etc/php.ini
/usr/local/lsws/lsphp72/etc/php.ini
/usr/local/lsws/lsphp71/etc/php.ini
/usr/local/lsws/lsphp70/etc/php.ini
/usr/local/lsws/lsphp56/etc/php.ini
/usr/local/lsws/lsphp55/etc/php.ini
/usr/local/lsws/lsphp54/etc/php.ini
/usr/local/lsws/lsphp53/etc/php.ini

I have fixed that but I couldn’t find how to install Zip-Extension to extract modules for PHP in CyberPanel. Do you have any idea or reference? I have tried many ways, it didn’t work tho.