skip to Main Content

I’m running Ubuntu 18.04 with nginx/1.14.0. I have been running PHP 7.2 but some of my web applications require a newer php for security reasons.

Since it is nginx, I use PHP-FPM.

I used apt to upgrade to the latest version of PHP.

# /usr/bin/php -v
PHP 8.0.2 (cli) (built: Feb 14 2021 14:21:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies

So that looks right. But the application still complains about PHP-FPM 7.2 and phpinfo confirms:

PHP Version 7.2.34-13+ubuntu18.04.1+deb.sury.org+1

So it sounds like I should change the PHP conf file. Here’s what I get when I try to find it:

# locate php.conf | more
/etc/nginx/snippets/fastcgi-php.conf

OK. So I seek php.ini:

# locate php.ini | more
/etc/php/7.2/cli/php.ini
/etc/php/7.2/fpm/php.ini
/etc/php/7.2/fpm/php.ini.orig
/etc/php/7.2/fpm/php.ini.ucf-dist
/etc/php/8.0/apache2/php.ini
/etc/php/8.0/cli/php.ini
/etc/php/8.0/fpm/php.ini
/usr/lib/php/7.2/php.ini-development
/usr/lib/php/7.2/php.ini-production
/usr/lib/php/7.2/php.ini-production.cli
/usr/lib/php/8.0/php.ini-development
/usr/lib/php/8.0/php.ini-production
/usr/lib/php/8.0/php.ini-production.cli

I am not seeing a conf file that would make the choice for NGINX or PHP where I would tell it to use PHP-FPM 8.0.

How do I get NGINX/PHP to use the new version of PHP that is on my server instead of the old one?

2

Answers


  1. You need to update the relevant PHP packages. You update the cli package, but that’s not enough.

    Check which packages are installed for 7.2:

    dpkg --get-selections | grep -v deinst | grep php | grep 7.2
    

    and if, say, you find php7.2-foo, try installing php8.0-foo. Try then also removing the 7.2 version.

    Be sure to run an apt-get update beforehand.

    Some packages (I think one is xdebug, and maybe redis?) have weird dependencies, in that installing the 8.0 will also (re)install the 7.2. That’s okay. But you’ll probably just need the FPM one(s), and those should be trouble-free.

    Login or Signup to reply.
  2. in each server, you can define which version of PHP, Nginx should use:

    location ~ .php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      }
    

    or :

    location ~ .php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php8.0-fpm.sock;
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search