AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 490255
Accepted
dzhi
dzhi
Asked: 2013-03-22 12:58:53 +0800 CST2013-03-22 12:58:53 +0800 CST 2013-03-22 12:58:53 +0800 CST

Apache 在默认情况下工作时不会在 VHOST 上解析 PHP

  • 772

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

接下来我创建了新用户并复制/粘贴默认 vhost 文件并使用a2ensite启用它并且只为该新用户相应地调整路径但由于某些原因未解析 PHP 文件并且仅显示它们的源。

所以,回顾一下:相同的虚拟主机设置,启用 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

这是我的默认虚拟主机文件内容:

<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会是这个问题的罪魁祸首吗?

apache-2.2
  • 2 2 个回答
  • 3907 Views

2 个回答

  • Voted
  1. dsznajder
    2013-03-22T16:01:03+08:002013-03-22T16:01:03+08:00

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

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

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

    • 0
  2. Best Answer
    dzhi
    2013-03-23T10:53:37+08:002013-03-23T10:53:37+08:00

    耶!开始工作了!

    在 /etc/apache2/mods-enabled/php5.conf 检查 Apache 的 PHP 模块 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,瞧:

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

    • 0

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve