Apache 默认在 VHOST 上工作,但无法解析 PHP

Apache 默认在 VHOST 上工作,但无法解析 PHP

我设置了一个 Debian 6 VPS 来托管几个小网站,对于默认网站来说,它运行得很好。

接下来我创建了新用户并复制/粘贴默认 vhost 文件并启用它a2ensite并且只针对新用户调整路径,但由于某种原因,PHP 文件无法解析,只显示其源文件。

因此,回顾一下:相同的 vhost 设置,启用 PHP 模块,打开短标签(但未使用)

要说清楚的是:我在这里和其他地方的网络上搜索并找到了很多“解决方案”,但这些解决方案似乎都不适合我。

刚刚注意到日志中的这个字符串:

PHP Fatal error:  Unknown: Failed opening required '/home/tester/public_html/index.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0

[Thu Mar 21 20:28:55 2013] [error] [client xxx.xxx.xxx.xxx] PHP Warning:  Unknown: open_basedir restriction in effect. File(/home/tester/public_html/index.php) is not within the allowed path(s): (/home/user/public_html:/tmp) in Unknown on line 0

这是我的默认 vhost 文件内容:

<VirtualHost *:80>

        ServerAdmin [email protected]
        ServerName domain.com
        ServerAlias www.domain.com
        DocumentRoot /home/user/public_html/
        ErrorLog /home/user/logs/error.log
        CustomLog /home/user/logs/access.log combined

        <Directory "/home/user/public_html">
        AllowOverride All
                php_admin_flag engine on
                php_admin_value open_basedir "/home/user/public_html:/tmp"
        </Directory>

</VirtualHost>

PHP 可以open_basedir是这个问题的罪魁祸首吗?

答案1

是的,open_basedir 可能是此问题的根源。路径中必须有 /home/tester/public_html/,并且有 /home/user。

看起来它跳过了 PHP 解析并且没有像我所想的那样阻止对页面的访问 - 我发现类似的问题在这里得到解决:https://bbs.archlinux.org/viewtopic.php?id=57877

/据我所知,第一个版本要求澄清的内容已被删除,因为不符合 ServerFault 政策。/

答案2

好极了!成功了!

检查了 Apache 的 PHP 模块配置设置 /etc/apache2/mods-enabled/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
    Order Deny,Allow
    Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
    Order Deny,Allow
    Deny from all
</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_value engine Off
    </Directory>
</IfModule>

它明确指出:

# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.)

所以我这样做了,然后重新启动了 Apache,然后:

https://i.stack.imgur.com/Be7dj.png

相关内容