我有 Apache 2在我的 Raspberry Pi 上安装了 PHP,当我请求 index.php
时它加载正常,但是当我尝试请求任何子文件夹或任何其他文件时(strandsort.cs
在此示例 - 也可以是 anything.txt,只是不是要解析的 HTML/PHP),我得到 403 access denied
,但是当我请求应该解析的文件时(i2.php
) 我得到一个空白页。
可能还值得注意的是,phpmyadmin
似乎工作正常。
我配置的配置是:
/etc/apache2/sites-enabled/000-default
并将AllowOverride
设置为ALL
。
这是错误:
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/
其中“RaspberryIP”是设备的 IP 地址。
最佳答案
错误是:
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
只是一个符号链接(symbolic link)的真实文件。默认的 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
中——原始发帖者也在评论中提供——它说:
[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/
这样的全面权限更改可以解决问题,但有时最好知道确切的问题出在哪里,这样你对真正发生的事情感到困惑。
关于php - Apache 无法在 Raspberry Pi 上打开页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23458424/