Change PHP version with Nginx

SYSTEM INFORMATION
OS type and version Ubuntu Linux 20.04.4
Webmin version 1.994
Virtualmin version 7.1-1
Related packages php, nginx

Hello! I am trying to change the version of PHP on my server. I can’t seem to change it at the domain or subdomain levels.

As you can see from the attached screenshot, there is no default selection for PHP script execution mode, nor is there a default website directory, like there used to be.

I tried changing the execution mode to FCGId, hit Enabled on the PHP Versions and filled in / as the Website subdirectory, but no dice.

Help!

I can’t see any screenshot. have you tried Virtualmin > Server Configuration > PHP Options? My LEMP stack Nginx have PHP version selection there.

Ah, yes, it would’ve been good to actually include that. This is what I see in the PHP Options setting:

As you can see, there’s no default set for FPM vs. FCGId, nor any default website (like in the old configuration), and nothing I put in there seems to stick or have any impact.

It doesn’t look like any php execution mode is selected. I see it have FPM preselected when opening the PHP Options page

Exactly my point – it should have a mode pre-selected, but does not. It seems as if there’s no connection between that screen and what is happening on my server. The site itself indicates it’s running 7.4.30, regardless of what I do on that screen.

I am not sure, though it may have to do with this piece of information:

While that topic is going for a php version for a specific path, it also mentions the option is to disappear, Who knows that may be the reason for no default version being marked / recognized in the configs.

We will set all new install default to PHP-FPM with Virtualmin 7.2, as of now the default was mod_php (must never be used nowadays).

Does the issue disappear if you choice either of the modes first, preferably PHP-FPM, and hit save button? After it’s saved, go back to PHP Options page – does it get displayed correctly?

Sadly i can not fully recall what has happened, it was on a production system and some quick fiddling around in the config files itself made it work as expected,

I just recall noticing the same “no selection of any option” happening. experience / using virtual/webmin for a fair few years has thought me to not make changes using virtualmin if things get displayed in strange ways and use manual configs to fix things beforehand, as making changes while things are displayed wrong often gives unpredictable results.

For me virtualmin is more of a helper tool as i can / do most things on the console / configs directly.

It does not, in my case. It goes through the motions of updating, but when the option screen comes back, there is still nothing selected.

As a workaround, is there a way to manually set this in the config? I don’t want to risk breaking Virtualmin, but I need the other version of PHP.

I do not think this is really a good solution for “beginners”, though this vultr link and this rocky linux guide might get you some insights on what it may involve to manually configure.

The pages are really incompatible with how web/virtualmin tends to setup and isolate users in configurations. so be careful if you proceed. If able let the support team try and find the proper bug fix for you as it also helps to prevent even more complicated issues down the line.

Yes, I am quite conversant with manual configuration. I was more asking if there was a workaround that doesn’t break Virtualmin.

Thanks for the links, regardless!

That shouldn’t be done.

By the way — did you install Virtualmin properly using install.sh -b LEMP command?

I did. I followed the instructions on the Virtualmin site.

Alright then, what is the output of the following command:

dpkg -l | grep php
ii  libphp7.4-embed                    1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        HTML-embedded scripting language (Embedded SAPI library)
ii  php-cgi                            2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          server-side, HTML-embedded scripting language (CGI binary) (default)
ii  php-cli                            2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          command-line interpreter for the PHP scripting language (default)
ii  php-common                         2:92+ubuntu20.04.1+deb.sury.org+2                                    all          Common files for PHP packages
ii  php-fpm                            2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          server-side, HTML-embedded scripting language (FPM-CGI binary) (default)
ii  php-gd                             2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          GD module for PHP [default]
ii  php-gnupg                          1.5.1-1+ubuntu20.04.1+deb.sury.org+10                                amd64        PHP wrapper around the gpgme library
ii  php-mbstring                       2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          MBSTRING module for PHP [default]
ii  php-mysql                          2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          MySQL module for PHP [default]
ii  php-pear                           1:1.10.13+submodules+notgz+2022032202-2+ubuntu20.04.1+deb.sury.org+1 all          PEAR Base System
ii  php-xml                            2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii  php-zip                            2:8.1+92+ubuntu20.04.1+deb.sury.org+2                                all          Zip module for PHP [default]
ii  php7.4-bcmath                      1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        Bcmath module for PHP
ii  php7.4-bz2                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        bzip2 module for PHP
ii  php7.4-cgi                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        server-side, HTML-embedded scripting language (CGI binary)
ii  php7.4-cli                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        command-line interpreter for the PHP scripting language
ii  php7.4-common                      1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        documentation, examples and common module for PHP
ii  php7.4-curl                        1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        CURL module for PHP
ii  php7.4-fpm                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.4-gd                          1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        GD module for PHP
ii  php7.4-gnupg                       1.5.1-1+ubuntu20.04.1+deb.sury.org+10                                amd64        PHP wrapper around the gpgme library
ii  php7.4-json                        1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        JSON module for PHP
ii  php7.4-mbstring                    1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        MBSTRING module for PHP
ii  php7.4-mysql                       1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        MySQL module for PHP
ii  php7.4-opcache                     1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        Zend OpCache module for PHP
ii  php7.4-pspell                      1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        pspell module for PHP
ii  php7.4-readline                    1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        readline module for PHP
ii  php7.4-soap                        1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        SOAP module for PHP
ii  php7.4-xml                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        DOM, SimpleXML, XML, and XSL module for PHP
ii  php7.4-xmlrpc                      1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        XMLRPC-EPI module for PHP
ii  php7.4-zip                         1:7.4.30-3+ubuntu20.04.1+deb.sury.org+1                              amd64        Zip module for PHP
ii  php8.1-bcmath                      8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        Bcmath module for PHP
ii  php8.1-bz2                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        bzip2 module for PHP
ii  php8.1-cgi                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        server-side, HTML-embedded scripting language (CGI binary)
ii  php8.1-cli                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        command-line interpreter for the PHP scripting language
ii  php8.1-common                      8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        documentation, examples and common module for PHP
ii  php8.1-curl                        8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        CURL module for PHP
ii  php8.1-fpm                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.1-gd                          8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        GD module for PHP
ii  php8.1-imagick                     3.7.0-2+ubuntu20.04.1+deb.sury.org+2                                 amd64        Provides a wrapper to the ImageMagick library
ii  php8.1-intl                        8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        Internationalisation module for PHP
ii  php8.1-mbstring                    8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        MBSTRING module for PHP
ii  php8.1-mysql                       8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        MySQL module for PHP
ii  php8.1-opcache                     8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        Zend OpCache module for PHP
ii  php8.1-pspell                      8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        pspell module for PHP
ii  php8.1-readline                    8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        readline module for PHP
ii  php8.1-soap                        8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        SOAP module for PHP
ii  php8.1-xml                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        DOM, SimpleXML, XML, and XSL module for PHP
ii  php8.1-xmlrpc                      3:1.0.0~rc3-4+ubuntu20.04.1+deb.sury.org+10                          amd64        XML-RPC servers and clients functions for PHP
ii  php8.1-zip                         8.1.8-1+ubuntu20.04.1+deb.sury.org+1                                 amd64        Zip module for PHP
ii  webmin-php-pear                    1.5                                                                  all          Webmin module for PHP Pear Modules

I unfortunately couldn’t reproduce your issue. Although, I would suggest purging libphp7.4-embed package by running apt-get purge libphp7.4-embed – I doubt you really need this package installed.

Save all installed packages to install-packages.txt by running:

dpkg -l | grep ^ii > install-packages.txt

… and attach this file to this ticket by drag and dropping it in reply box.

Also, how does the site Nginx config look like? This is a file under /etc/nginx/sites-enabled directory?

Can you save this file first and also attach to this ticket (you can replace actual domain name with example.com). After the file is preserved, can you go to Edit Virtual Server and disable both Nginx website and Nginx SSL website features and then re-enable them on the second shot? This would re-generate Nginx config for a domain. Does this help to sort PHP cannot be changed issue?

Lastly, does it work if you try using CLI to change execution mode by running:

virtualmin modify-web --domain example.com --mode fpm

configs.zip (28.8 KB)

I do, because I code my own PHP extensions.

Attached.

It looks like this may be the problem. I looked at other sites in my VirtualMin config, where I haven’t done any custom modification of the Nginx configuration, and the option to select PHP is normal. On this one site, I have a customized file, and it is not working. The custom conf is attached.

It seems odd that it doesn’t work, though. I mean, it should just be replacing the following line, right?

fastcgi_pass unix:/var/php-nginx/1620371197244018.sock/socket;

Here’s the output:

Updating server example.com ..
    Changing PHP execution mode to fpm ..
    .. done

    Saving server details ..
    .. done

.. done

Restarting PHP-FPM server ..
.. done

And no, it doesn’t work.

I’ve attached the requested files as a zip archive – your forum doesn’t like text files, it seems.
configs.zip (28.8 KB)

Okay, so finally got around to trying out the disable/enable approach. Interestingly, it did not entirely regenerate the base Virtualmin config files for Nginx, but instead maintained my original files. Now when I try to access the site, it says “502 Bad Gateway.”

I tried restarting the PHP 8.1 FPM service; no dice. I changed it from FPM to FCGId, and it works, but is running PHP 7.4.3. Went back in, changed it to PHP 8.1, with FCGId, still says it’s running 7.4.3.

Changed it back to FPM – note that when I change it to FPM or FCGId, there is no option to select the version. I have to do it afterwards. This time, without changing anything, it registers as 8.1.

So, basically, the fix appears to be:

Disable the Nginx site and SSL site.
Enable them.
Switch from FPM to FCGId.
Switch it back to FPM.

And then it works.

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