6

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?

PHPdabbler
  • 63
  • 3

2 Answers2

4

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;
  }
Raskul
  • 1,674
  • 10
  • 26
  • maybe you want to look at this link too. https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04 – Raskul Feb 21 '21 at 23:20
  • 1
    Thank you. This worked. I got into the `/etc/nginx/sites-available/*` files and changed each instance where `fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;` was stipulated and replaced it with `fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;`. And restarted the nginx service. And now phpinfo() reports php 8.0 and my app that wanted PHP-FPM 8.0 is happy. Thanks again! – PHPdabbler Feb 22 '21 at 02:48
  • @PHPdabbler you're welcome, but I suggest creating a file in /etc/nginx/conf.d/nuxt.info.conf (https://nuxt.info is my website, you make a file name for your website), and after that put all the codes related to your website inside it like https://laravel.com/docs/8.x/deployment#nginx Nginx will read all the files with .conf suffix in the 'conf.d' folder – Raskul Feb 22 '21 at 03:07
0

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.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • 1
    Thank you for this suggestion. I chose to try the other answer first because it seemed easier and less risky. – PHPdabbler Feb 22 '21 at 02:43
  • That's okay. But the "risk" is truly negligible, you probably currently just have two separate PHP-FPM installations and one PHP-CLI installation (the command above will tell you whether this is the case). At worst, you get some extra disk space used for modules you're not really using - which, on the other hand, is the situation you're in now :-) – LSerni Feb 22 '21 at 11:57
  • I forgot! - all the above holds, *unless* you **need** two different versions of PHP installed, which **is** a common requirement (if you, for example, need to maintain an older PHP codebase together with a recent one). When that is the case, my solution is worthless and actually damaging, as it will disable older PHPs; and you need to tune Nginx conf files instead (@SamRaskul's answer). – LSerni Feb 22 '21 at 12:00