Multiple PHP Versions, but not adhering selected version in CLI

Operating system: Ubuntu
OS version: 18.04.5 LTS

So I’ve installed 7.3, 7.4 and 8.0 alongside 7.2 that was installed by default with the help of:

I’ve then gone ahead and followed:

I’ve ran the ‘re-ran’ twice now, just to be sure, with the following result:

The following PHP versions are available : 7.2.34 (/usr/bin/php-cgi7.2), 7.3.26 (/usr/bin/php7.3), 7.4.14 (/usr/bin/php7.4), 8.0.1 (/usr/bin/php-cgi8.0), 8.0 (mod_php)
The following PHP execution modes are available : mod_php cgi fcgid fpm
The following PHP-FPM versions are available on this system : 7.2.34 (php7.2-fpm) 8.0.1 (php8.0-fpm)

I’ve set-up the individual virtual server to use 7.4.14

But it doesn’t adhere the version I selected as shown on # php -v
PHP 8.0.1 (cli) (built: Jan 13 2021 08:21:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies

At ‘Website options’ I’ve selected “FCGId (run as virtual server owner)” and “CGI wrapper (run as virtual server owner)” to try this.

When I select “FPM (run as virtual server owner)” it drops back to “7.2.34” as that and 8.0 are the only versions select-able.

What am I missing to activate the PHP version that I’ve selected when using either “FCGId (run as virtual server owner)” or “CGI wrapper (run as virtual server owner)”.

I’ve also used the commands I saw as ‘notices’:

a2enmod proxy_fcgi setenvif
a2enconf php7.2-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.3-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
a2enmod proxy_fcgi setenvif
a2enconf php8.0-fpm
systemctl restart apache2

As a ‘last resort’ and the rule it out, I’ve also restarted my VPS but no changes.


After changing the execution mode for PHP, you’ll need to reset the PHP version. I recently noticed this when I was addressing a PHP issue on a clients server.

Best Regards,
Peter Knowles | TPN Solutions


But it doesn’t adhere the version I selected as shown on

If you want to change server global default PHP version (when called from console) you must use:

update-alternatives --config php

Those options you see in Virtualmin UI applied to given virtual server only.

If you want a virtual server to use specific PHP version in cli or when running Cron jobs you would want the caller to use the full path to PHP executable.

1 Like

@tpnsolutions thanks for you’re reply, I’ve tried switching execution modes and changing PHP versions afterwards but without luck, I’ve just now run the following:

 virtualmin modify-web --domain --php-version 7.4                                                                 Updating server ..
    Saving server details ..
    .. done

.. done

Applying web server configuration ..
.. done

But PHP 8.0.1 - phpinfo() still shows the PHP (cli) version of the host.

@Ilia thanks for you’re reply too! I don’t mind which version the global default is, the selection I’ve made for the virtual server doesn’t apply to the virtual server as it seems to use the host version.

I shouldn’t need to run update-alternatives --config php to get my virtual server to use php 7.4 instead of 8.0 as that is what it seems to listen too at the moment.


The following seemed to work on a customer’s server…

virtualmin modify-web --domain --mode fpm

Followed by…

virtualmin set-php-directory --domain --dir . --version 7.4

After those commands executed, going to “Server Configurations” > “Website Options” indicated that the PHP execution mode had been set to “FPM”.

And going to “Server Configurations” > “PHP Versions” indicated the default PHP version was set to “7.4”.

*** We also installed a test script to print the “phpinfo()” in order to confirm it was using the proper PHP version and execution mode as well. ***

Best Regards,
Peter Knowles | TPN Solutions

1 Like

It would be wonderful if this could be made part of Virtualmin’s GUI.



It is part of the GUI. If you go to the pages I noted above in the Virtualmin GUI, you could technically do all of this within the GUI. I just love doing stuff on the CLI, also I had written a wrapper script to execute these two commands across all domains in a single execution… So there was that too.

*** I also like exposing the CLI API to people as many aren’t even aware of its existence or powerful capabilities. ***

Best Regards,
Peter Knowles | TPN Solutions

1 Like

Ah, yes. I responded to Illia’s message and had just reached yours which was further down the thread. That’s a useful combination of commands, @tpnsolutions that you have shared with us. :+1:

It would be a big help to know, if it were clearly stated in the Virtualmin GUI, which version is in force where, and, of course, the option to set an alternative available version for the virtual server as well as for the system at CLI (for cron etc.).


If you visit:

"Server Configuration" > "Website Options"

you will see the “execution mode” and also be able to change it.

If you visit:

"Server Configuration" > "PHP Versions"

you will see the current version setup as the “default” and can even set different versions on a directory basis.

Best Regards,
Peter Knowles | TPN Solutions

1 Like

Perhaps we are talking at cross-purposes @tpnsolutions. Changing this does not help @danielb1990 change the version reflected at php -v

@calport @danielb1990,

Running scripts on the command line, and running scripts through the browser differ as scripts on the command line (CLI) run using the global PHP configuration which @Ilia has already explained how to change, and websites use the localize PHP configuration for that domain located in “/home/user/etc/”.

Anyways, I was going over instructions for “websites” not CLI which was already covered by @Ilia quite nicely.

Best Regards,
Peter Knowles | TPN Solutions

1 Like

Thanks! Strangely enough, the php7.X-fpm wasn’t installed correctly, so I forced a -reinstall of both:
apt install -y php7.4-fpm php7.3-fpm --reinstall

Which made the right files and I was able to successfully switch to 7.4 or any of the other versions I’ve installed.

Not quite sure what caused that initially but it works now, thanks everyone.

How I did it:

  1. Go to your home dir

cd ~

  1. Edit .bash_profile with your editor of choice and add this alias:

alias php=‘/usr/bin/php74’

  1. Save and exit. Then update the config:

. ~/.bash_profile

  1. Now run check on PHP version active:

php -v

If everything is OK you’ll see something like:

PHP 7.4.15 (cli) (built: Feb 2 2021 14:19:57) ( NTS ) Copyright (c) The PHP Group

You can set this on each user profile by editing their profile config.
I’m on CentOS 7. Hope it helps.

1 Like

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