Php Apache不会在Raspberry Pi上打开页面

Php Apache不会在Raspberry Pi上打开页面,php,apache,raspberry-pi,http-status-code-403,Php,Apache,Raspberry Pi,Http Status Code 403,我已经在Raspberry Pi上安装了PHP,当我请求index.PHP时,它可以正常加载,但当我尝试请求任何子文件夹或任何其他文件(strandsort.cs在本例中,也可以是anything.txt,而不是要解析的HTML/PHP)时,我会得到403拒绝访问,但当我请求应该解析的文件(i2.php)时,我得到一个空白页面 同样值得注意的是,phpmyadmin似乎工作正常 我在中配置了配置: /etc/apache2/sites-enabled/000-default 并将AllowOv

我已经在Raspberry Pi上安装了PHP,当我请求
index.PHP
时,它可以正常加载,但当我尝试请求任何子文件夹或任何其他文件(
strandsort.cs
在本例中,也可以是anything.txt,而不是要解析的HTML/PHP)时,我会得到
403拒绝访问
,但当我请求应该解析的文件(
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
只是一个符号链接。默认的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>
编辑:原始海报发布了
ls-la
输出,如下所示:

-rw------- 1 pi www-data 21 May  1 14:10 /var/www/i2.php
这似乎是正确的,但我建议至少尝试调整权限,以便所有人都可以像这样读取该文件:

<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>
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!";
?>
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/
这样的全面权限更改可以解决这个问题,但有时最好知道确切的问题是从哪里来的,这样你就不会对真正发生的事情感到困惑。

+1提供问题解决技术供将来使用。
ls-la/var/www/i2.php
prints:
-rw------1pi www-data 21 May 1 14:10/var/www/i2.php
access.log相当长,这里是:哦,文件归默认用户所有,因为我使用ftp上传它们。这里是
/etc/apache2/sites available/default
内容:问题是权限问题。运行Apache的用户是什么?该文件上的
stat
的结果是什么?@gd1
stat
对于类似的东西来说太过分了。一个简单的
ls-la/var/www/i2.php应该就足够了。@JakeGould。是的,估计服务器会停止30秒,否则:)@gd1好吧,这不是服务器负载问题,而是用户理解问题。我一直使用
ls-la
来处理用户/组/权限问题。我只在做更深层的事情时使用
stat
,比如
bash
脚本来修改、更改或访问时间。实际上,我有点讽刺。)
[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