dpd3447 2011-10-29 15:31
浏览 31
已采纳

PHP包括总是失败

  • Apache HTTP Server 2.2.21 with VirtualHosts under SuExec
  • PHP 5.3.8 via fcgid
  • Arch Linux 2011.08.19

I am in the process of migrating from shared hosting to VPS. The code I had ran fine before the move but is now failing at this line:

require_once($_SERVER['DOCUMENT_ROOT'] . 'includes/content/header.php');

Error log says:

PHP Fatal error: require_once(): Failed opening required '/srv/www/hostname/public/includes/content/header.php' (include_path='.:/usr/share/pear') in /srv/www/hostname/public/index.php on line 3

I tried the same line without the document root part, with and without ./, etc. with no luck. No difference with require, include_once, or include, either. Yet, I can verify that the file exists at that exact location by copy-pasting from the error log and cding to it…

But just to be absolutely sure, I tested the return values of the includes as well as file_exists—they all return false. Yet all of the files are chown'd by the SuExec user/group, and no combination of permissions helps (on directories or files); have tried from 644 to 777. What's going on here?

Edit:

  • Same result with files in the same directory.
  • Apache & SuExec error logs reports nothing.
  • Safe Mode is set to "Off" in php.ini.
  • dirname(__FILE__) and exec('pwd') return the same as $_SERVER['DOCUMENT_ROOT'] but without the trailing slash.
  • fread, file_get_contents, and realpath(dirname(__FILE__)) all return false.
  • set_include_path() has no effect.
  • Running require via php-cgi directly from the command line returns Internal Server Error while include returns blank output; running either via php returns blank output.

Here's my vhost config:

<VirtualHost *:80>
    ServerAdmin admin@hostname.com
    DocumentRoot "/srv/www/hostname/public/"
    ServerName hostname.com
    ServerAlias www.hostname.com
    SuexecUserGroup hostname hostname
    ErrorLog "/srv/www/hostname/logs/error.log"
    LogLevel debug
    CustomLog "/srv/www/hostname/logs/access.log" combined

    <Directory /srv/www/hostname/public>
        Order allow,deny
        Allow from all
    </Directory>

    # http://www.linode.com/forums/viewtopic.php?t=2982
    <IfModule !mod_php5.c>
    <IfModule !mod_php5_filter.c>
    <IfModule !mod_php5_hooks.c>
    <IfModule mod_actions.c>
    <IfModule mod_alias.c>
    <IfModule mod_mime.c>
    <IfModule mod_fcgid.c>
        AddHandler php-fcgi .php
        Action php-fcgi /fcgid-bin/php-fcgid-wrapper
        Alias /fcgid-bin/ /srv/www/hostname/fcgid-bin/

        <Location /fcgid-bin/>
            SetHandler fcgid-script
            Options +ExecCGI
            Order allow,deny
            Allow from all
        </Location>

        ReWriteEngine On
        ReWriteRule ^/fcgid-bin/[^/]*$ / [PT]
    </IfModule>
    </IfModule>
    </IfModule>
    </IfModule>
    </IfModule>
    </IfModule>
    </IfModule>
</VirtualHost>
  • 写回答

5条回答 默认 最新

  • douren1891 2011-12-15 05:23
    关注

    Circling back to post the solution:

    I didn't realize that open_basedir was unaffected by Safe Mode being off—it was looking in /srv/http/ but not /srv/www/, which would be the containing directory for /srv/www/hostname/public/includes/content/.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c