5

I have a web-server running multiple server (virtual hosts) using nginx and fastcgi passing to a unix-socket.

What I want to accomplish is a set-up with beta.example.com and live.example.com, where the live site has error_reporting turned off (but still logs to file), and on the beta-site error_reporting is on.

So with Apache I would do something in the lines of:

<VirtualHost *:80>
    ServerName beta.example.com

    [...]

    php_flag display_errors on
    php_flag display_startup_errors on
    php_value error_reporting -1

    [...]
</VirtualHost>

When googling I haven't found anything where I can pass this kind of parameters to PHP using fastcgi. Does anyone know how to do this?

The configuration right now is (simplified):

server {
    server_name beta.example.com;
    [...]
    fastcgi_pass unix:/var/run/nginx/php-fastcgi.sock;
    fastcgi_index index.php;
}
1
  • Have you tried pho.ini a google search brings up quite a few results, have have you found so far? Nov 27, 2013 at 13:15

3 Answers 3

4

You can pass these options to PHP fastcgi from nginx with this syntax:

fastcgi_param PHP_FLAG "display_errors=on \n display_startup_errors=on";
fastcgi_param PHP_VALUE "error_reporting=-1";

Note the newline (\n) character that has to be between the passed options.

3
  • I think, also, that the spaces should not be there. Nov 27, 2013 at 17:10
  • this does absolutely nothing for me. I had to add to php.ini directly for my setting. Is there a reason why the fastcgi_param PHP_FLAG will not work with Nginx? Do I need to turn something else on in PHP or Nginx? I put the setting in my location { } block Jul 3, 2015 at 23:01
  • This might not work for the op's actual question. He wanted different settings per virtual server, which [maybe] isn't possible without creating separate PHP-FPM pools for each server. (There is conflicting information about this, and no official documentation, but that seems to maybe be the case.)
    – orrd
    Aug 6, 2016 at 0:42
0

For some reason PHP_FLAG for had no effect for me, but suddenly this line worked:

fastcgi_param   PHP_VALUE       "display_errors=on \n display_startup_errors=on \n error_reporting = E_ALL \n error_log = /var/log/nginx/foo-bar.error.log";

nginx/1.11.6, php / php-fpm 5.6.31-4

0

You can run another php-fastcgi process with another socket and use the config snippet from your post with the new socket. Another advantage is more isolation, you can for example run the second php process under an user, which does not have the access rights to mess with the production website.

The nginx side would look like this:

server {
    server_name production.example.com;
    [...]
    fastcgi_pass unix:/var/run/nginx/php-fastcgi.sock;
    fastcgi_index index.php;
}
server {
    server_name beta.example.com;
    [...]
    fastcgi_pass unix:/var/run/nginx/php-fastcgi-beta.sock;
    fastcgi_index index.php;
}

The php side depends on how you start the php fastcgi processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.