One can set error_reporting in nginx.conf like so:
fastcgi_param PHP_VALUE error_reporting=E_ALL;
But if I do this in one server block, will it affect all the others as well? Should I change php settings in all server blocks simultaneously?
PHP-FPM (FastCGI Process Manager) is an alternative to FastCGI implementation of PHP with some additional features useful for sites with high traffic. It is the preferred method of processing PHP pages with NGINX and is faster than traditional CGI based methods such as SUPHP or mod_php for running a PHP script.
Nginx uses PHP FPM and php. ini is usually located in /etc/php/8.1/fpm/php. ini .
FastCGI is a protocol based on the earlier CGI, or common gateway interface, protocol meant to improve performance by not running each request as a separate process. It is used to efficiently interface with a server that processes requests for dynamic content.
You can set PHP_VALUE per server and this will affect that server only.
If you need equal PHP_VALUE for all your servers with PHP, use include files.
For example (debian), create /etc/nginx/conf.d/php_settings.cnf:
fastcgi_param PHP_VALUE "upload_max_filesize=5M;\n error_reporting=E_ALL;";
Then include this file into any server or location config you need:
server {
...
location ~ \.php$ {
...
include /etc/nginx/conf.d/php_settings.cnf;
}
...
}
If every host on your server runs in its own PHP-FPM pool, than adding fastcgi_param PHP_VALUE ... to one nginx host will not affect the other ones.
If on the other hand all nginx hosts use one PHP-FPM pool, you should specify PHP_VALUE for every host you have (error_reporting=E_ALL for one of them, empty value for others). Since fastcgi_param passes PHP_VALUE if specified, and doesn't pass if not. In a while all workers will have PHP_VALUE=error_reporting=E_ALL, unless you explicitly set PHP_VALUE in other hosts.
Additionally, fastcgi_param PHP_VALUE ... declarations override one another (the last one takes effect).
Steps to reproduce:
apt install nginx php5-fpm
/etc/nginx/sites-enabled/hosts.conf:
server {
server_name s1;
root /srv/www/s1;
location = / {
include fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param PHP_VALUE error_reporting=E_ERROR;
}
}
server {
server_name s2;
root /srv/www/s1;
location = / {
include fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
Add s1, s2 to /etc/hosts
Change pm to static, pm.max_children to 1 in /etc/php5/fpm/pool.d/www.conf
cat /srv/www/s1/index.php:
<?php var_dump(error_reporting());
systemctl restart php5-fpm && systemctl restart nginx
curl s2 && curl s1 && curl s2
int(22527)
int(1)
int(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With