duanlei5339 2014-12-16 17:46
浏览 42
已采纳

包括php不工作linux apache2 [关闭]

Good day. Maybe, it's a duplicate, but I didn't found an answer for me. I have developed a PHP site on local server (Apache2.4, Windows) and all were working. Including files isn't working on Debian VPS server with apache2. What can cause this problem?

<? include '/include/libs.php';?>
  • 写回答

1条回答 默认 最新

  • douxian1923 2014-12-16 18:14
    关注

    Three reasons I'm guessing
    First:

    You may not have privileges/permissions to access the file your trying to include.
    Usually, this is the very error involved with failed include statements.
    Try running this code:
    <?php var_dump(substr(sprintf('%o', fileperms('/include/libs.php')), -4)); ?> If the last three digits of output are less than 7, 5 and 5 respectively then you're caught up in a file permission problem.
    You can resolve this error by changing the including file(s) permissions in bash
    sudo chmod -R 0755 /var/www/include/libs.php
    Use sudo chmod 0755 /var/www/html/include/libs.php instead, if, your apache version is above 2.4
    Note that you need to use the -R flag for chmod so that all your enclosing folders are also chmodded.

    Second:
    You are not running php as the default apache2 user-group OR your includee file belongs to root.
    This, like the previous reason is also file permission exception.
    run sudo chown "www-data" /var/www/include/libs.php OR sudo chgrp "www-data" /var/www/include/libs.php followed by sudo service apache2 restart in bash.

    Third:
    You may have screwed your apache2/PHP installation/configuration settings.
    Hit sudo apt-get purge php5 and the sudo apt-get install php5 in bash.
    Keep in mind that his WILL burn all your custom php.ini settings and you may need to start configuring right from the beginning. [ I learned this the hard way :D ].

    Hope this helps ...

    UPDATE:
    After i read that there is no error shown,
    it occurred to me you have the default php5 config ...
    open sudo gedit /etc/php5/apache2/php.ini
    Change the line display_errors = Off to display_errors = On
    This was the problem I had when I installed php from scratch ...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝