php - 使用 PHP-FPM 时可以覆盖 htaccess 中的 PHP 设置吗?

标签 php apache .htaccess

我的虚拟主机是这样的:

<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 错误日志中:

/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 设置?

蒂亚。

最佳答案

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

但是PHP似乎有一个类似的机制,名为.user.ini文件。

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.

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.

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

在下面的评论中

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

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 样式格式。

关于php - 使用 PHP-FPM 时可以覆盖 htaccess 中的 PHP 设置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38190279/

相关文章:

php - 使用 PHP 删除字符串的一部分

java - 使用 Apache POI 的 SXSSFSheet 从 xlsx 读取数据

apache - 为什么 mod_rewrite 从我的请求 url 中删除端口号?

zend-framework - 在子目录主机上部署模块化 zend 项目

php - 选择仅具有一个不同列的重复行并将其分组

php - 按数据库中的选定列排序

mysql - Ubuntu Apache 服务器中的 HDD 空间即将耗尽

apache - 服务器配置 : app/etc/local. xml 拒绝客户端

.htaccess - 如何将所有请求重定向到文件,除了使用 Apache 的图像?

php - 基本分页