apache不能运行任何php


apache cannot run any php

我在我的树莓pi上安装了一个apache服务器,除非我尝试提供php,否则一切似乎都运行得很好。

/var/www/html/index.html serves fine
/var/www/html/foo/index/index.html serves fines

但如果我添加index.php,我们可以说:

<?php echo "hello world"; ?>

我通过访问/var/www/html获得了403-Forbbiden,但我仍然可以访问/var/wwwww/html/foo/index.html(目录索引设置为php.html.htm)。

如果我运行$php index.php:hello world

所以,它可以服务.html,可以运行.php,但不能服务.php。

我该怎么解决这个问题?我找到了很多解决方案,但没有一个对我有效。

注:我从局域网访问这些站点。服务器操作系统(uname-a):Linux raspbian AH 4.1.19-v7+#858 SMP 3月15日星期二15:56:00 GMT 2016 armv7l GNU/Linux

正如评论中所说,我们可以很容易地推断出模块没有加载,但我在这里是:

pi@raspbian-AH:/etc/apache2/mods-available $ cat php5.conf 
<FilesMatch ".+'.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+'.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^'.ph(p[345]?|t|tml|ps)$">
    Require all denied
</FilesMatch>
# Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

和php5.load:

pi@raspbian-AH:/etc/apache2/mods-available $ cat php5.load
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

多亏了dan08,我发现我的设置在某种程度上搞砸了。因此,我没有找出问题所在,而是清除了所有内容并重新安装。反正没有什么可保存的。

所以解决方案是:

sudo apt-get purge apache2 php5 libapache2-mod-php5
sudo apt-get install apache2 php5 libapache2-mod-php5