How to make new PHP version a system default?

SYSTEM INFORMATION
OS type and version AlmaLinux 9.2
Webmin version 2.101
Virtualmin version 7.8.2

This question has been asked here couple of times, but I can’t find a decent answer.

I got PHP 8.0 with AlmaLinux 9.2 package. I’m running Laravel 10, which requires PHP 8.2. I installed it following this instructions: Multiple PHP Versions – Virtualmin.

Laravel works, no problems, even php --version on the CLI shows 8.2 version. But PHP 8.0 “ghost” is giving headeache.

For example, when I run composer update to get new libraries, it automatically takes PHP 8.0, which then generates errors (since Laravel is expecting 8.2). Yes, I know, I can use syntax “/usr/bin/php82 /usr/local/bin/composer update”, but I’d rather not.

The other problem is to use “su root” and running php commands. Root is using the system default version 8.0, and usually I need 8.2.

This can’t be that difficult? I just want to get rid of PHP 8.0, entirely, and use only 8.2 - for all virtual servers in the system. Or, alternatively, change the system default to PHP 8.2 and forget 8.0 for good.

I know someone here knows how to do that. Please, share your wishdom. And please, no workarounds, I think I know them all, and they won’t make me happy :slight_smile:

Thanks in advance, More / Helsinki

…and to continue, this workaround is not perfect either:

  1. Go to /usr/bin
  2. rename phpphp80
  3. create symbolick link, which points from /usr/bin/php → /opt/remi/php82/root/usr/bin/php

It works for a while. All php commands, anywhere, with any account, run the 8.2 version. Until there’s an update for the 8.0 PHP package, which will recreate /usr/bin/php

Still waiting for pointers or the solution, thanks!

I have seen this mentioned before, the update-alternative command for changing your default PHP version. I have not tried this and I do not know if it breaks virtualmin.

Same question. Any ideas how to change php version? I use 8.1.2 but I wanto to change to 8.2. Thank’s

This is the right way to install and setup additional PHP version:

https://www.virtualmin.com/documentation/web/multiplephp/

It definitely does not break Virtualmin. Virtualmin is not written in PHP and doesn’t use PHP for anything.

It might break your apps if they have CLI/cronjobs that depend on php pointing to a specific version other than what you change it to. You can solve that by changing those usages to explicitly include a version, e.g. php82.

Note alternatives does not change what Virtualmin considers the default. For that, you can choose it in Server Templates->PHP Options. Nearly any “how do I change the default X that is configurable on a per-domain basis” in Virtualmin is answered by looking in Server Templates. I’d encourage y’all to poke around in there, just for the overview of the system it’ll give you. (Note that since it is a template option, you can have many “defaults”. i.e. you could make a “Old PHP” template for your customers that are running some cranky old application and need PHP 7.x, while everybody else gets a normal template with a new PHP version.)

Edit: I’ll also mention that I don’t use alternatives for this. I just make sure I explicitly call the version of PHP I need for CLI and cron stuff, so that it can’t be broken by some distant action later (like changing links or whatever that alternatives might do).

Yeah, I also wouldn’t rely on alternatives. However, if the default shell is called, for example when a user logs in via SSH, the PHP version used by default, i.e. when called php, would be extracted based on /etc/profile.d/virtualmin-phpalias.sh profile.

That said, probably the better way to call PHP directly in CLI would be using ~/bin/php or $HOME/bin/php, so if the PHP version change at some point in PHP Options page, then the expected PHP version would still be called.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.