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 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改