Custom settings with PHP

Hello,

I have setup PHP with spawn-fcgi, PHP work well, but how to pass custom
settings to PHP per virtualhost ?

Like this, for example (.htaccess get from RoundCube webmail) :

“php_value upload_max_filesize 5M”

Thanks for your replies,

Regards

On Friday 13 November 2009 14:22:55 you wrote:

Hello,

I have setup PHP with spawn-fcgi, PHP work well, but how to pass custom
settings to PHP per virtualhost ?

Like this, for example (.htaccess get from RoundCube webmail) :

“php_value upload_max_filesize 5M”

Thanks for your replies,
The only way I see is to set up a extra instance of spawn-fcgi with a
different
php.ini
The same problem happens when you try to simulate suexec …

Micha

On Fri, 13 Nov 2009 14:22:55 +0100, Life Hunter wrote:

I have setup PHP with spawn-fcgi, PHP work well, but how to pass custom
settings to PHP per virtualhost ?

Like this, for example (.htaccess get from RoundCube webmail) :

“php_value upload_max_filesize 5M”

This works just fine:

location /somewhere {
fastcgi_param ENV_NAME “Value for Somewhere”;
}
location /else {
fastcgi_param ENV_NAME “Value for somewhere else.”;
}

If you are setting something that php doesn’t read from its environment,
just use ini_set() with $_SERVER or $_ENV. If the value you want isn’t
PHP_INI_ALL, there might be another way to get it in; too bad php-cgi
environment usage seems undocumented in the manual.

I see no reason why this shouldn’t work with a server block, too, for
virtual host. Try also nginx’s max request size parameters for your use
case.

N.b., most/all fastcgi settings don’t in if () {} blocks. That would be
a feature request on my part, particularly to set different timeouts for
GET and POST requests.

Posted at Nginx Forum:

[color=#FF0000]UPDATE[/color]

Now, it is possible to do this way:

fastcgi_param  PHP_VALUE  "upload_max_filesize=5M";

More information here:
http://bugs.php.net/bug.php?id=51595

Using this technique, I have successfully set different “error_log”
locations for multiple virtual hosts.

Thanks, PHP and NginX guys!

Posted at Nginx Forum:

You can add or override fastcgi params you just have to understand the
behavior of the array.

Also afaik _ENV is only for cli. Use _SERVER instead. Also php 5.3 has
overrides built in now on the user level and you cam use htscanner.
Because some settings you won’t be able to change via ini_set either.

Sent from my iPhone

On Fri, Jun 18, 2010 at 08:23:16AM -0400, jbruni wrote:

Using this technique, I have successfully set different “error_log”
locations for multiple virtual hosts.

One note, you should not concatenate using “set”:

set $php_value “pcre.backtrack_limit=424242”;
set $php_value “$php_value \n pcre.recursion_limit=99999”;
fastcgi_param PHP_VALUE $php_value;

You can do it just in place:

fastcgi_param PHP_VALUE “pcre.backtrack_limit=424242 \n
pcre.recursion_limit=99999”

or

fastcgi_param PHP_VALUE “pcre.backtrack_limit=424242
pcre.recursion_limit=99999”;

or to minimize spaces:

fastcgi_param PHP_VALUE “pcre.backtrack_limit=424242
pcre.recursion_limit=99999”;


Igor S.
http://sysoev.ru/en/

2010/6/18 Igor S. [email protected]:

So basically space or linebreak delimited?

On Fri, Jun 18, 2010 at 09:12:51AM -0700, Michael S. wrote:

So basically space or linebreak delimited?

I believe that linebreak. This is not nginx’s feature, but PHP’s one.

fastcgi_param PHP_VALUE “upload_max_filesize=5M”;
set $php_value “pcre.backtrack_limit=424242”;
pcre.recursion_limit=99999";


nginx mailing list
[email protected]
nginx Info Page


Igor S.
http://sysoev.ru/en/

On Fri, Jun 18, 2010 at 9:18 AM, Igor S. [email protected] wrote:

On Fri, Jun 18, 2010 at 09:12:51AM -0700, Michael S. wrote:

So basically space or linebreak delimited?

I believe that linebreak. This is not nginx’s feature, but PHP’s one.

Yeah, according to Jérôme’s comment on bugs.php.net, it needs \n

So it looks like \n is okay, spaces are not (but isn’t that the FPM
SAPI processing it anyway? Couldn’t it actually accept anything with
any delimiter you put in the SAPI Jérôme?)

2010/6/18 Michael S. [email protected]:

SAPI processing it anyway? Couldn’t it actually accept anything with
any delimiter you put in the SAPI Jérôme?)

yes you need to use \n to separate. This way the code hack to make it
works is quite simple (we can reuse as is the INI parsing stuff). If
we want to use another delimiter (space, comma), it’ll be quite more
difficult to code and certainly more difficult to test and valid. I’m
notre sure we want to go with this.

2010/6/18 Jérôme Loyet [email protected]:

yes you need to use \n to separate. This way the code hack to make it
works is quite simple (we can reuse as is the INI parsing stuff). If
we want to use another delimiter (space, comma), it’ll be quite more
difficult to code and certainly more difficult to test and valid. I’m
notre sure we want to go with this.

that’s cool. was just throwing ideas out there. it does look a little
bit ugly in nginx configuration to do that :frowning: but it is a VERY useful
option.

does this work for PHP_INI_SYSTEM? so it can override -any- variable?
or only things that could be done normally via ini_set()?

So anything that can be done only via htaccess in apache. Its not the
same level as an fpm configuration override which is system level? Since
this is being passed at runtime to already established fpm workers…

2010/6/18 Michael S. [email protected]:

option.

does this work for PHP_INI_SYSTEM? so it can override -any- variable?
or only things that could be done normally via ini_set()?

It’s supposed to be exactly as php_value, php_flag, php_admin_value
and php_admin_flag from the apache sapi

Igor S. Wrote:

[/code]

More information here:
PHP :: Request #51595 :: passing ini settings via FASTCGI parameters

Igor, how about using the current values of PHP_INI* variables inside
the definition e.g.:

fastcgi_param PHP_ADMIN_VALUE
“open_basedir=/opt/www/mysite:${open_basedir}”;

Currently, it doesn’t work and nginx complains about the ${open_basedir}
variable, as the server treats it as nginx variable:

  • Checking nginx’ configuration …
    nginx: [emerg] unknown “open_basedir” variable
    nginx: configuration file /etc/nginx/nginx.conf test failed

Any workaround for this or a hidden possibility to refer to current
values of PHP_INI variables?

Andrejs

Posted at Nginx Forum:

hobson42 Wrote:

There is no reason why Nginx should know the CGI
had to find.
Ian, I think you misunderstood me. I did not mean that nginx should
figure out the current value of PHP variable, but it should allow to
pass constructs like ${varname} into the environment, so that the
upstream FCGI manager, for example PHP-FPM, would then be able to
substitute variables accordingly. Eg:

fastcgi_pass PHP_VALUE
“include_path=${include_path}:/my/other/include/path”;

I am not sure if PHP-FPM is able to do that at present, but, at least,
it allows such constructs in its own confirguration:

php_value[include_path] = “${include_path}:/my/other/include/path”

So I would assume the same could have been possible with PHP_VALUE
settings for FastCGI environment.

Andrejs

Posted at Nginx Forum:

On 12 Jul 2011 14h54 WEST, [email protected] wrote:

port defined on a match.
would have to read even if it could know it was a
“include_path=${include_path}:/my/other/include/path”;
In your fastcgi_params file (or whatever you named it) do:

fastcgi_param PHP_VALUE
“include_path=${include_path}:/my/other/include/path”;

This was introduced on PHP
5.3.3. Cf.
http://michaelshadle.com/2011/02/11/setting-php-ini-parameters-from-nginx

— appa

On 09/07/2011 23:59, locojohn wrote:

fastcgi_param PHP_VALUE
“upload_max_filesize=5M”;
[/code]

More information here:
PHP :: Request #51595 :: passing ini settings via FASTCGI parameters

Igor, how about using the current values of PHP_INI* variables inside
the definition e.g.:

This is impossible. Think about what nginx does - It matches filenames
to a mask and passes the request using CGI to the port defined on a
match.

There is no reason why Nginx should know the CGI server is php (It is
only convention that php files end in .php) and no reason why it should
be php
either - it might be Ruby, Python, Erlang, or anything else you might
use. Further there is no way it can determine which php.ini file it
would have to read even if it could know it was a php configuration it
had to find.

Ian

On 12 Jul 2011 15h23 WEST, [email protected] wrote:

It matches filenames
use. Further there is no way it can determine

fastcgi_pass PHP_VALUE
“include_path=${include_path}:/my/other/include/path”;

In your fastcgi_params file (or whatever you named it) do:

fastcgi_param PHP_VALUE
“include_path=${include_path}:/my/other/include/path”;

Make that:

fastcgi_param PHP_VALUE
“include_path=${include_path}:/my/other/include/path”;

Hmm, never tried that, using a variable. Don’t know if the $ needs to
be escaped.

You’ll have to try it.

— appa

On 12 Jul 2011 15h40 WEST, [email protected] wrote:

and

fastcgi_param PHP_VALUE
“include_path=${include_path}:/my/other/path”;

and neither works, hence I wrote here.

From here PHP :: Request #51595 :: passing ini settings via FASTCGI parameters it’s implied that you
cannot use variables in the headers. PHP variables that is. You can
use Nginx variables.

Best solution I think is to create a new parameter $my_include_path.
Set it on fastcgi_params and then do a:

fastcgi_param PHP_VALUE my_include_path=/my/include/path;

ini_set(‘include_path’, ini_get(‘include_path’) . ‘:’ .
$my_include_path);

on your script.

— appa