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?
Advertisement
Answer
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; }