2015-11-25 108 views
0

我需要帮助解决,有什么说是在htdocs文件夹的权限错误,因为我需要改变他们甚至在首位添加文件夹。require_once:未能打开流:权限被拒绝(LAMPP)

这是我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 

回答

3

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

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

感谢您的时间试图帮助我。

0

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

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

如果我明白你说的是 “/opt/lampp/lampp/htdocs/project/helpers/system_helper.php” 应该工作,我是对吗? 编辑:我会发布我与include_once –

+0

错误现在它只是说没有这样的文件或目录 –

+0

是的。这应该工作。但是请注意,如果这是您的文档根目录而不是/ opt,那么您的路径从/ htdocs开始,这意味着如果必须将它放在代码中,那么您的路径将为/project/helpers/system_helper.php。尽管你应该尝试以编程的方式获得绝对路径,正如我在答案中所建议的那样。 –

1

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

<?php 

require_once '../test.php'; 

echo ' you'; 

test.php只包含echo "hello";导致预期 “你好你”。

我猜你的问题是文件权限。你能检查你的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

应该给你的权限运行该脚本。

+0

这就是当我键入它说: “LS -ld /选择/ LAMPP/htdocs目录” drwxrwsrwx 6根WWW 4096 11月16日23:18的/ opt/LAMPP/htdocs目录 –

+0

,这就是当我键入“LS它说-ld/opt/lampp/htdocs/PHP-Wizard“ --drwxr-xr-x 12 xy www 4096 Nov 25 21:34/opt/lampp/htdocs/PHP-Wizard/ –

+0

这些是我对系统帮助程序的许可.php:-rw ------- 1 xy xy 1518 –

0

打开终端,粘贴,执行这些命令:

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

当然,当收到提示后sudo -i

现在你的要求,包括将工作输入密码!

+0

谢谢!我是新来的stackoverflow,我不知道如何格式化文本:P – Jackson

相关问题