php - 使文件扩展名由 PHP 解释

标签 php apache .htaccess mod-fcgid

我将其添加到我的 .htaccess 文件中:

AddHandler fcgid-script .test

(我正在使用 FastCGI/VirtualMin/WebMin)

并用内容创建了一个 test.test 文件;

<?php echo "test"; ?>

这会导致内部服务器错误,并在错误日志中显示此消息:

[Thu Apr 16 14:12:57.631287 2015] [fcgid:warn] [pid 2646] (104)Connection reset by peer: [client xxxx:53595] mod_fcgid: error reading data from FastCGI server
[Thu Apr 16 14:12:57.631402 2015] [core:error] [pid 2646] [client xxxx:53595] End of script output before headers: test.test

我做错了什么?我尝试使用不同的处理程序名称,例如 x-httpd-php 或 x-httpd-php5,但这根本没有任何作用。

我也试过:

<FilesMatch "\.test$">
  SetHandler fcgid-script
</FilesMatch>

但它有相同的内部服务器错误。

最佳答案

FastCGId 模块似乎不知道如何执行您的脚本 - FcgidWrapper似乎缺少指令(因为您的 PHP 脚本没有 Shebang )。

根据您的发行版,您必须手动设置它,或者您可以调整已经处理 .php 文件的现有指令以也处理 .test 文件(通常这应该使用“SetHandler fcgid-script”指令和设置来完成/复制 FcgidWrapper 指令)。

调整后的示例(取自 https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples):

<FilesMatch "\.test$">
    AddHandler fcgid-script .test
</FilesMatch>
Options +ExecCGI
FcgidWrapper /usr/bin/php5-cgi .test

更多信息和示例:https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#exampleshttp://tltech.com/info/php-on-fcgid/

其他问题可能基于权限,例如如果您使用的是 suexec,则 fastcgid 进程无法写入日志或无法执行包装脚本。如果您能说明正常的 .php 文件是否正确执行,这将非常有帮助。

关于php - 使文件扩展名由 PHP 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29691853/

相关文章:

php - 带有大写和小写符号的 .htaccess 和 href 链接

apache - 无法通过 UBUNTU 12.10 上的本地 IP 地址访问 Web 服务器

php - PHP 脚本中未输出 XML

Javascript 函数内的 PHP 变量输出变量而不是值

php - Apache URL 重写 & 所有请求均由同一 PHP 文件运行

java.lang.NoSuchMethodError : org. apache.tomcat.util.ExceptionUtils.unwrapInitationTargetException

PHP exec 命令运行 python 脚本但不运行 python3

.htaccess - 的意思 ?和 htaccess 重写规则中的 $

php - 网页抓取字体访问问题

caching - Nginx memcache 缓存和失效