使用PHP-FPM时可以覆盖htaccess中的PHP设置吗? [英] Can I Override PHP Setting in htaccess When Using PHP-FPM?

查看:116
本文介绍了使用PHP-FPM时可以覆盖htaccess中的PHP设置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的虚拟主机看起来像这样:

My vhost looks like this:

<Directory "/var/www">
  Options Indexes FollowSymlinks MultiViews
  AllowOverride All
  Require all granted

  <FilesMatch "\.php$">
    Require all granted
    SetHandler proxy:fcgi://127.0.0.1:9000
  </FilesMatch>
</Directory>

我正在尝试将php_value行添加到我的.htaccess文件中.这样做后,我立即收到500个错误,这在我的Apache错误日志中:

I'm trying to add php_value lines to my .htaccess file. As soon as I do, I get 500 errors, and this in my Apache's errors log:

/var/www/.htaccess:无效的命令"php_value",可能拼写错误或 由服务器配置中未包含的模块定义

/var/www/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

所以,问题是:使用PHP-FPM时,是否可以通过.htaccess覆盖php.ini设置?

So, the question: Is there any way to override php.ini settings via .htaccess, when using PHP-FPM?

tia.

推荐答案

正如其他人已经指出的,不,使用PHP-FPM时无法通过.htaccess覆盖设置.

As others already pointed out, no, you can't override settings via .htaccess when using PHP-FPM.

但是PHP似乎有一种类似的机制,名为 文件.

But there seems to be a similar mechanism from PHP, named .user.ini files.

自PHP 5.3.0起,PHP包括对每个目录的配置INI文件的支持.这些文件仅由CGI/FastCGI SAPI处理.此功能使PECL htscanner扩展无效.如果您使用的是Apache,请使用.htaccess文件以达到相同的效果.

Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.

除了主要的php.ini文件外,PHP还会从每个请求的PHP文件的目录开始,扫描每个目录中的INI文件,并一直处理到当前文档的根目录(在$ _SERVER ['中设置) DOCUMENT_ROOT']).如果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 (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.

在.user.ini样式的INI文件中,只能识别具有PHP_INI_PERDIR和PHP_INI_USER模式的INI设置.

Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.

在下面的评论中

如果您使用的是Apache,请使用.htaccess文件以达到相同的效果."

"If you are using Apache, use .htaccess files for the same effect."

为澄清起见,这仅适用于Apache模块模式.如果将php伪指令放在Apache CGI/FastCGI服务器上的.htaccess中,则会以500错误将服务器炸毁.

To clarify, this applies only to Apache module mode. If you put php directives in .htaccess on an Apache CGI/FastCGI server, this will bomb the server out with a 500 error.

因此您可以创建类似.htaccess的.user.ini文件,但格式为ini样式.

So you can create .user.ini files analogue to .htaccess, but in ini style format.

这篇关于使用PHP-FPM时可以覆盖htaccess中的PHP设置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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