Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

The website still runs the old PHP after you installed a newer PHP-FPM

Errorphpinfo() in the browser reports an older PHP Version than php -v

Short answer

With PHP-FPM, the web server hands each .php request to a pool, and the pool belongs to one PHP version. Installing a new version changes php -v, not the pool the site talks to. Change the address in fastcgi_pass (nginx) or SetHandler (Apache), validate the config, and reload.

  • Applies to nginx 1.26, Apache 2.4, PHP-FPM 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the web server itself. A throw-away file prints the version and the interface that served it. The word fpm-fcgi means a PHP-FPM pool answered, and apache2handler would mean Apache's own module instead.

    # put the file in the document root of the affected site
    echo '<?php echo PHP_VERSION, " ", PHP_SAPI;' | sudo tee /var/www/example.com/public/whoami.php
    curl -s https://example.com/whoami.php
    php -v | head -n 1
    sudo rm /var/www/example.com/public/whoami.php
  2. 2Match what you see, then jump to its fix

    1. 1The first-step output ends in fpm-fcgi with the old version, and the site's nginx config has a fastcgi_pass line.nginx passes the request to the pool of the old versionFix
    2. 2The version is old, PHP_SAPI is fpm-fcgi, and the Apache config has a SetHandler line that begins with proxy:unix or proxy:fcgi.Apache hands .php files to the old pool through mod_proxy_fcgiFix
    3. 3You edited fastcgi_pass, nothing changed, and the config test prints an error or you forgot to reload.The new setting never took effect because nginx kept the old configurationFix

What does the error look like?

  • phpinfo() in the browser reports an older PHP Version than php -v
  • PHP_SAPI prints fpm-fcgi and the version is not the one you installed last

Cause 1 of 3

nginx passes the request to the pool of the old version

1Check

fastcgi_pass sets the address of the FastCGI server, either host:port or a unix: socket path. Each version has its own pool with its own listen address, and different location or server blocks can name different ones. See which address your site uses and which sockets exist.

grep -rn "fastcgi_pass" /etc/nginx/
sudo ss -xlp | grep -i php

2Fix

Change fastcgi_pass to the listen address of the pool that belongs to the version you want. The pool's own config file shows that value in its listen directive.

location ~ \.php$ {
    # keep the other lines of your existing block
    fastcgi_pass unix:/path/from/the/new/pool/listen/directive.sock;
}

3Verify

Test the config, reload nginx, and request the file again.

sudo nginx -t && sudo systemctl reload nginx
curl -s https://example.com/whoami.php

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

Apache hands .php files to the old pool through mod_proxy_fcgi

1Check

With PHP-FPM, Apache needs mod_proxy and mod_proxy_fcgi, and a SetHandler line names the pool socket. A leftover line from the previous version keeps pointing at the old one.

grep -rn "proxy:unix\|proxy:fcgi" /etc/apache2/
apache2ctl -M | grep -i proxy

2Fix

Replace the socket in the SetHandler line with the listen address of the new version's pool, keeping the rest of the line as it is.

<FilesMatch "\.php$">
    SetHandler "proxy:unix:/path/from/the/new/pool/listen/directive.sock|fcgi://localhost/"
</FilesMatch>

3Verify

Test the Apache config, reload it, and request the test file again.

sudo apache2ctl configtest && sudo systemctl reload apache2
curl -s https://example.com/whoami.php

Confirmed by httpd.apache.org

Did this fix it?

Cause 3 of 3

The new setting never took effect because nginx kept the old configuration

1Check

nginx reads its configuration again only when it is told to. If the new configuration cannot be applied, it carries on with the old one, so the old pool keeps answering. Run the test and read its last lines.

sudo nginx -t

2Fix

Fix whatever the test reports, then reload so the master process applies the new file.

sudo nginx -t
sudo systemctl reload nginx

3Verify

The test output ends in a success line, and the test file shows the new version.

curl -s https://example.com/whoami.php

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • After each PHP upgrade, request a whoami.php-style file through the web server and compare it with php -v.
  • Keep one fastcgi_pass or SetHandler address per site, in one included file, so there is a single line to change.
  • Remove the old PHP-FPM version once no site uses it, so a stale address fails loudly instead of answering quietly.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Servers

Cookies from a PHP backend vanish behind an nginx proxy

Login works when you call the backend directly but fails through nginx

nginx forwards Set-Cookie headers from the backend unchanged, so lost cookies usually come from the cookie itself: a domain or path that does not match the public URL, or Secure and SameSite flags the browser rejects.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.