.user.ini文件是否可用于子目录? [英] Does the .user.ini file work for subdirectories?

查看:227
本文介绍了.user.ini文件是否可用于子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制文件夹特定的PHP设置的.user.ini文件是否也属于子文件夹?

Does the .user.ini file that controls folder specific PHP settings also descend into the subfolders?

我正在阅读一些网站,但他们建议这样做(尽管没有很多相关信息),但是我发现如果我从子文件夹运行脚本,它将不会使用.user.ini文件.

I was reading a few websites and they suggest that it does (albeit there is not alot of information about it), however I've found that if I run a script from a subfolder, it doesn't use the settings from the .user.ini file.

我是否缺少某些内容,或者仅是用于执行脚本的文件夹?如果是这样,是否有一种方法可以使php脚本从父文件夹等中查找.user.ini文件?

Am I missing something or is it only meant to be for the same folder that the script is executing from? If so, is there a way to make php scripts look for the .user.ini file from the parent folder etc?

推荐答案

是的,它应该可以工作.但是,我对.user.ini文件有同样的问题,没有递归设置php_value.根据php.net上的官方(简短的)文档,它们应该递归工作(如.htaccess一样):

Yes, it should work. However, I had the same issue with .user.ini files not setting php_value's recursively. According to official (and short) documentation on php.net they should work recursively (as .htaccess did):

PHP从目录开始扫描每个目录中的INI文件 所请求的PHP文件,并一直更新到当前版本 文档根目录(在$ _SERVER ['DOCUMENT_ROOT']中设置). 如果PHP文件位于文档根目录之外,则仅扫描其目录.

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 (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.

我发现Apache配置中的斜杠太多了,这导致.user.ini文件无法递归工作.

What I have found out is that Apache configuration had one trailing slash too much which caused .user.ini files not to work recursively.

看看您的 phpinfo(),特别是 SCRIPT_FILENAME 变量.请注意两个斜杠-应该只有一个:

Take a look at your phpinfo(), specifically SCRIPT_FILENAME variable. Notice two slashes - where should be just one:

$_SERVER['SCRIPT_FILENAME'] = //home/site/public_html/phpnfo.php

其原因来自apache config,其中包含一个过多的斜杠.

The reason for this was coming from apache config, which contained one trailing slash too much.

<IfModule !mod_php5.c>
    <FilesMatch \.php$>
            SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost/"
    </FilesMatch>
    DirectoryIndex index.php index.html index.htm
</IfModule>

Apache config不包含目录的尾部斜杠,因此应使用 fcgi://localhost/代替 fcgi://localhost/,如下所示:

Apache config doesn't include trailing slashes for directories so instead of fcgi://localhost/ this should be written as fcgi://localhost like this:

<IfModule !mod_php5.c>
    <FilesMatch \.php$>
            SetHandler "proxy:unix:/var/lib/php/php-fpm.sockets/site.sock|fcgi://localhost"
    </FilesMatch>
    DirectoryIndex index.php index.html index.htm
</IfModule>

更改后,重新启动Apache/php-fpm,您已设置好.

After change, restart Apache/php-fpm and you are set.

更新:事实证明,Apache配置中的尾部斜杠错误仍然很常见,并可能导致不同的错误和错误的php做法(例如,在DocumentRoot /var/www/web/中设置).

Update: As it turns out, trailing slash errors in Apache config are still common thing and can lead to different errors and bad php practices (eg set in DocumentRoot /var/www/web/ ).

这篇关于.user.ini文件是否可用于子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆