php's .user.ini with nginx and subdirectory

独自空忆成欢 提交于 2019-12-13 06:11:19

问题


Setup

I have installed nginx 1.2.2 and PHP 5.4.4. I have configured PHP with nginx running as FastCGI.

nginx config snippet:

location ~ \.php$ {
    root           E:/Websites/localhost;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  E:/Websites/localhost/$fastcgi_script_name;
    include        fastcgi_params;
}

I have a number of local virtual sites running on same system. To customize each ones requirements I have created .user.ini file in each sites root folder which as per the PHP documentation should be applicable on sub folders also.

Please note this is a development environment and not live. So I have flexibility to customize a number of things.

Problem

When I access any site from the browser it works fine unless I do not dive into some sub folder. It seems that .user.ini does not work in sub directories - at least in my configuration.

As per PHP document (http://www.php.net/manual/en/configuration.file.per-user.php):

In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root

SOS

Has anyone configured .user.ini under nginx - request you to please help me out.

Note: Someone reported a bug in 2009: https://bugs.php.net/bug.php?id=50374

More Information (EDIT)

PHPInfo() says (in root as well as in sub folders):
* Server API: CGI/FastCGI
* user_ini.filename: .user.ini (local as well as master)

php_sapi_name() says cgi-fcgi

These values are present in phpinfo() from root folder and sub directories. So there is no difference in PHPInfo().

Further confirmation that it is running as CGI/FastCGI is that root folder is taking configurations from .user.ini but not sub folders.

// .user.ini
auto_prepend_file = "E:\Websites\localhost\user.ini.php"

and

// user.ini.php
<?php
printf('Hi from: %s', __FILE__);
?>

This may actually be a bug but has anyone configured PHP with nginx in this way and did not faced the problem. Requesting to please share version numbers and platform in this case.


回答1:


You only partially quoted the PHP docs you linked to. It also says These files are processed only by the CGI/FastCGI SAPI.

I suspect you are not using the CGI/FastCGI SAPI but some other SAPI ... the PHP-FPM SAPI perhaps?

As you may have figured from the above, running FastCGI is not equivalent to using the CGI/FastCGI SAPI. You can also run FastCGI using other SAPIs such as PHP-FPM.

BTW SAPI = Server API. You can look for yours in a phpinfo file.




回答2:


This is actually a much bigger issue then just nginx, but a permanent solution is available. The alternative ini_set method of adding directive options has significant limitations so it is not really a good long term solution. Thanks. http://www.ait-pro.com/aitpro-blog/4349/misc-projects/wordpress-tips-tricks-fixes/php5-3-x-php5-4-x-user-ini-file-does-not-work-known-php5-3-x-user-ini-fastcgi-wordpress-zend-issue/



来源:https://stackoverflow.com/questions/11360042/phps-user-ini-with-nginx-and-subdirectory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!