require_once:无法打开流:权限被拒绝(lampp)

时间:2015-11-25 22:22:47

标签: php permissions lampp

我需要帮助解决,htdocs文件夹中的权限错误,因为我需要更改它们甚至首先添加文件夹。

这是我的init.php文件:

<?php
//Start Session
session_start();

//Include Configuration
require_once('config/config.php');

//Helper Function Files
require_once('helpers/system_helper.php');
require_once('helpers/format_helper.php');
require_once('helpers/db_helper.php');

//Autoload Classes
function __autoload($class_name){
require_once('libraries/'.$class_name . '.php');
}
?>

我尝试通过`

包含它

当我运行index.php文件时,我收到此错误:

Warning: require_once(../../htdocs/PHP-Wizard/helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Fatal error: require_once(): Failed opening required '../../htdocs/PHP-Wizard/helpers/system_helper.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

我尝试使用../向上移动一个文件夹,但它不起作用。

我四处寻找与我相似的错误,但没有运气。他们都说No such file or directory in (path)

可能是同一个错误,或者我真的需要更改我的权限,如果是这样,我该怎么做?

编辑:当我使用include_once('helpers/system_helper.php');时,我收到此错误:

Warning: include_once(helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Warning: include_once(): Failed opening 'helpers/system_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9

Warning: include_once(helpers/format_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10

Warning: include_once(): Failed opening 'helpers/format_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10

Warning: include_once(helpers/db_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11

Warning: include_once(): Failed opening 'helpers/db_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11

4 个答案:

答案 0 :(得分:7)

问题确实是权限,我猜是因为我复制了文件夹。

我在chmod 777上修复了该文件夹中的所有文件,现在工作正常。

感谢您抽出时间帮助我。

答案 1 :(得分:1)

我使用相对路径测试,它工作正常。

<?php

require_once '../test.php';

echo ' you';

test.php只包含echo "hello";导致预期的&#34;你好&#34;。

我猜你的问题在于文件权限。您可以查看system_helper.php上的权限吗?它至少应该由用户运行的php(通常是www-data)执行。我可以通过执行chown root test.phpchmod 600 test.php重现您的错误消息,所以我猜想像

chown www-data: system_helper.php

chmod g+rwx system_helper.php

应该授予你运行脚本的权限。

答案 2 :(得分:0)

require_once需要绝对路径,而不是相对路径。这应该有所帮助:

require_once realpath(dirname(__FILE__)."/helpers/system_helper.php");

答案 3 :(得分:0)

打开终端,粘贴并执行以下命令:

sudo -i
sudo chmod -R 777 var/www/html/*/*.*

当然,在sudo -i

之后提示时输入密码

现在您的要求和包含将起作用!