【问题标题】:htaccess php_value auto_prepend_file gives me internal 500 errorhtaccess php_value auto_prepend_file 给了我内部 500 错误
【发布时间】:2018-12-09 19:41:01
【问题描述】:

我对来自 htaccessphp_value auto_prepend_file 有疑问。它给了我 500 内部服务器错误。以下 htaccess 代码在 localhost 上运行良好,但在在线服务器上给我 500 Internal Server Error。问题出在哪里,解决方案是什么?任何人都可以在这方面帮助我吗?

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /script/

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,NE,L]

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ $1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^post/([\w-]+)/?$ sources/post.php?msgID=$1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]

php_value auto_prepend_file "/home/*****/public_html/script/path.php"

【问题讨论】:

  • @anubhava 亲爱的没有关于500错误的任何错误只有这个错误:File does not exist: /home/*****/public_html/404.shtml
  • 先检查下面的答案。我相信您的 htaccess 没有使用 Directory 指令。
  • @anubhava 错误是这样的:/home/******/public_html/script/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
  • @anubhava tobias-k 答案意味着您的赏金答案并非无处不在。我已经在我的本地主机上使用了你的答案。

标签: .htaccess


【解决方案1】:

为了使php_value 指令起作用,它需要一个环境,其中 PHP 作为模块加载到 Apache 网络服务器中。

情况不一定如此。例如,您的在线服务器可以通过 FCGI 将 PHP 请求转发给 FPM-worker,而无需在 Apache 中启用 mod_php

您可以在服务器上放置一个仅包含phpinfo() 的文件,以检查是否是这种情况。对我来说,它会在第三行显示Server API FPM/FastCGI

在这种情况下,无法通过.htaccess 覆盖php.ini 设置。您唯一的选择是更改 FPM/Pool 配置(假设您有权访问)或尝试ini_set

编辑:也可以使用 .user.ini 文件作为替代:https://medium.com/@jacksonpauls/moving-from-mod-php-to-php-fpm-914125a7f336 / https://secure.php.net/manual/en/configuration.file.per-user.php - 谢谢@anubhava

【讨论】:

  • 这部分我没看懂Your only options would be to change the FPM/Pool config (given you have access to that) or try ini_set.你能帮我解释一下吗?
  • 它的意思是指出它可以在 PHP-FPM 中设置非全局 php.ini 设置,但不像在 Apache 中使用 mod_php 那样容易,即使是非特权用户也可以使用.htaccess 文件来完成。您需要创建一个自定义工作池(然后获得一个 unix-socket 连接),并且可以在那里使用php_admin_value 来更改每个池的配置。当然,在您的 PHP 代码中始终可以使用 ini_set,但我意识到对于您的 auto_prepend_file 指令,这可能为时已晚。
  • 所以这意味着没有你的回答我不能使用它。因此,如果您有时间可以检查我的赏金问题吗? (这里)[stackoverflow.com/questions/47801948/… 我正在使用php_value auto_prepend_file 因为anubhavas 的回答。他的答案在每个本地主机上都可以正常工作。但无法正常工作的在线服务器
  • 错误日志也这样说:/home/******/public_html/script/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
  • 这正是您在我假设的情况下遇到的错误(mod_php 未启用):由未包含在服务器配置中的模块定义您检查了吗phpinfo()? 服务器 API 是什么?
猜你喜欢
  • 2011-08-04
  • 2013-05-02
  • 1970-01-01
  • 2018-01-05
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 1970-01-01
相关资源
最近更新 更多