错误是:
PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0, referer: http://raspberryIP/
PHP Fatal error: Unknown: Failed opening required '/var/www/i2.php' (include_path='.:/usr/share/php$ http://raspberryIP/
所以这似乎是文件/var/www/i2.php 的权限问题。哪个用户拥有该文件? Apache 能够读取该文件吗?如果从命令行运行此命令,输出是什么:
ls -la /var/www/i2.php
此外,Apache 错误日志说明了什么?它们应位于:
/var/log/apache2/access.log
/var/log/apache2/error.log
您可以使用tail 跟踪他们的输出,如下所示:
sudo tail -f -n 200 /var/log/apache2/access.log
sudo tail -f -n 200 /var/log/apache2/error.log
这些路径基于标准的 Ubuntu 12.04 安装,但对于 CentOS 和您在 Raspberry PI 中使用的任何 Debian 变体应该是相同的。
您知道,这个问题不是 Raspberry PI 设置的特殊问题,而是一个标准的 Linux Apache 服务问题。因此,用于成熟服务器的调试技术也可以在这里发挥作用。
另外,/etc/apache2/sites-available/default 文件的内容是什么?那是/etc/apache2/sites-enabled/000-default 只是一个符号链接的真实文件。默认的 Apache default 文件可能会令人困惑,并且包含许多冗余命令。这是我在 Ubuntu 中设置 Apache 时喜欢使用的精简版:
<VirtualHost *:80>
DocumentRoot /var/www
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
</VirtualHost>
注意这里没有AllowOverride All。 AllowOverride 的全部目的是允许解析 .htaccess 文件和在这个阶段不应该是一个因素。如果您觉得需要,可以将其添加到此配置中,如下所示:
<VirtualHost *:80>
DocumentRoot /var/www
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
编辑: 原发帖者发布了ls -la 输出,如下所示:
-rw------- 1 pi www-data 21 May 1 14:10 /var/www/i2.php
这似乎是正确的,但我建议至少尝试调整权限,以便所有人都可以像这样读取该文件:
sudo chmod a+r /var/www/i2.php
此外,在 Apache access.log(原始海报也在 cmets 中提供)中说:
[Sun May 04 18:00:02 2014] [error] [client 127.0.0.1] PHP Fatal error: Unknown: Failed opening required '/var/www/i2.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
这让我觉得i2.php 中的 PHP 编码有错误?你能检查那里的内容吗?也许只是创建一个简单的 PHP 文件,其中包含以下内容以查看会发生什么:
<?php
echo "Hello world!";
?>
说了这么多,也许你最好像这样调整整个 /var/www/ 目录的权限。
sudo chmod -R 755 /var/www/
755 将为所有者应用读取、写入和执行权限,并为组和其他人应用读取和执行权限。 -R 标志表明这应该在整个 /var/www/ 目录和子文件夹中递归。
另一个编辑:查看原始发布者的access.log,似乎可能存在与.htaccess直接相关的权限问题:
[Sun May 04 17:46:10 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:11 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:11 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:11 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:12 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:12 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sun May 04 17:46:12 2014] [crit] [client 192.168.1.2] (13)Permission denied: /var/www/js/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
因此,虽然对 /var/www/ 进行全面权限更改解决了问题,但权限问题是否也基于 /var/www/js/.htaccess 甚至父目录 /var/www/js/ ?我指出这一点的原因是,像sudo chmod -R 755 /var/www/ 这样的全面权限更改可以解决问题,但有时最好知道确切的问题出在哪里,这样您就不会对真正发生的事情感到困惑。