Currently, I have 3 PHP versions installed on the server:
5.4, 7.2, 7.3
When running the company php -v I’m getting PHP 5.4.16
I’m trying to understand how to assign a php version to CLI. I tried to follow what was suggested here:
But when running update-alternatives --list php I’m not getting a list of available versions.
Can anyone maybe help in guiding me on how exactly to do this?
Thanks in advance!
In a multi PHP setup there’s default PHP and then all others. Each has a cli but the ‘others’ need to be pointed to their binaries. To change the default PHP the one that uses /etc/php.ini needs to be changed.
Hey @ramin, thanks for your reply.
Unfortunately, this did not help me, I’m not sure if I am missing something or if it’s just not working as it should.
I followed the steps to change the default server PHP version in the server template setting page.
This would give you 7.3 output from the command php -v. But it doesn’t change how global/default PHP is set. Also consider how it affects 5.4.
Normally in a multi PHP setup, global PHP is the installation configured by /etc/php.ini no matter the version. To make 7.2 or 7.3 global, 5.4 would need to be replaced. You won’t be shifting things around in Virtualmin, you’ll need to upgrade or replace 5.4 with the newer version in a terminal using packages from SCL repository. I’m not much help with installing SCL PHP packages because I’m accustomed to Remi’s repo.
Let’s say you decide to take the long road and replace 5.4 with 7.3. First thing is to remove existing 7.3 because you don’t want it installed twice. Then, if you still need 5.4 you’ll have to reinstall it as an extra since it’s been replaced by global 7.3; 5.4’s install locations will be different than before and its .ini file would be /etc/opt/rh/rh-php54.ini instead of /etc/php.ini. The net benefits from juggling PHP installations this way won’t amount to much.
I bet the symlink solution is sounding pretty good at this point.
That’s kinda what I meant about considering how 5.4 would be affected, but (my bad) I didn’t consider myself that the 5.4 binary is in the way of the symlink. A different name for the symlink might work but it’s still a cheap workaround. If you absolutely want a newer PHP version as global default, the longer road is the cleaner way to do it.
But do you really need to? The cli for your extra PHP versions should be available, they just require longer paths, like this or similar (rh packages throw me off):
If there aren’t any issues with scripts or Virtualmin then I suggest don’t try to fix what aint broken.
It’s less a matter of removing the distro’s package than it is a matter of removing the default. Best not to remove the default installation but it can be upgraded. Take a deep dive into CentOS 7 tutorials and you’ll find it’s not unusual for PHP 5.4 to get an upgrade.
Thanks again for the detailed reply @ramin!
Actually, the reason why I’d like to have CLI on a higher php version is that I use Drupal 8 for the website hosted on this server, and some cron jobs require a higher php version to run.
This is the only reason why I started investigating this in the first please
I guess I will need to look more into updating the php 5.4 since this seems to be the “proper” way to go about this.