为什么 HTML 文件可以正确加载,而 PHP 文件不能


Why will HTML files load properly, while PHP files will not?

我有两个简单的测试文件,一个是显示简单消息的基本HTML文档,另一个是执行相同操作的PHP文档。

如果我使用这样的 URL 访问 HTML 文档,它会正确显示:

sample.com/test.html

如果我以类似的方式访问 PHP 文件,它也会正确显示:

sample.com/test.php

从子目录访问 HTML 文件也可以正常工作: sample.com/somedirectory/test.html

但是,以类似的方式访问 PHP 页面不起作用:

sample.com/somedirectory/test.php

它会产生此错误:

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。

请与服务器管理员联系,webmaster@samplehs.pltwcs.org 并告知他们错误发生的时间,以及您可能执行的任何可能导致错误的操作。

有关此错误的详细信息,请参阅服务器错误日志。

此外,在尝试使用错误文档处理请求时遇到 404 未找到错误。 编辑 以下是 HTML 代码:

<html>
    <body>
        hello world
    </body>
</html>

和PHP代码:

<?php
    phpinfo();
?>

以下是服务器的错误日志必须说的内容:

[Wed Dec 18 12:58:08 2013] [error] [client 71.222.168.54] File does not exist: /home/username/public_html/500.shtml
[Wed Dec 18 12:58:08 2013] [error] [client 71.222.168.54] SoftException in Application.cpp:256: File "/home/username/public_html/somedirectory/test.php" is writeable by group
您必须将

PHP文件的权限设置为644,将文件夹的权限设置为755,因为您的服务器已启用suEXEC

从终端,您应该运行chmod 644 test.php或使用任何FTP客户端来设置您的权限

源来源 #2

根据错误File "/home/username/public_html/somedirectory/test.php" is writeable by group您的服务器正在使用类似 suphp 的东西,您需要从命令行中删除 group: chmod go-w /home/username/public_html/somedirectory/test.php 的写入权限。