[英]require_once: failed to open stream: Permission denied(lampp)
I need help solving , what says to be a permission error in the htdocs
folder, because i needed to alter them to even add folders in the first place.我需要帮助解决
htdocs
文件夹中的权限错误,因为我首先需要更改它们以添加文件夹。
This is my init.php
file:这是我的
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');
}
?>
I try to include it via `我尝试通过`包含它
When i run my index.php
file i get this error:当我运行
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
I tried going one folder up with ../
, but it doesn't work.我尝试使用
../
将一个文件夹../
一个文件夹中,但它不起作用。
I looked around for a similar error to mine, but no luck.我环顾四周寻找与我类似的错误,但没有运气。 They all say
No such file or directory in (path)
.他们都说
No such file or directory in (path)
。
Could it be that it is the same error, or do i really need to change my permissions, if so, how can i do that?可能是同样的错误,还是我真的需要更改我的权限,如果是这样,我该怎么做?
Edit: When i use include_once('helpers/system_helper.php');
编辑:当我使用
include_once('helpers/system_helper.php');
i get this error:我收到此错误:
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
The problem was indeed the permissions, i'm guessing because i copied the folder. 问题确实是权限,我猜是因为我复制了文件夹。
I fixed it by chmod 777
on all the files in that folder, and now it works fine. 我通过
chmod 777
修复了该文件夹中的所有文件,现在它工作正常。
Thank you for your time attempting to help me. 感谢您抽出时间帮助我。
I tested using relative paths and it works fine. 我测试使用相对路径,它工作正常。
<?php
require_once '../test.php';
echo ' you';
Where test.php
just contains echo "hello";
test.php
只包含echo "hello";
resulted in the expected "hello you". 导致了预期的“你好”。
I would guess your problem is with file permissions. 我猜你的问题是文件权限。 Can you check what permissions are on your
system_helper.php
? 你能检查一下
system_helper.php
上的权限吗? It should be at least executable by the user php is running as (usually www-data). 它至少应该由用户运行的php(通常是www-data)执行。 I could reproduce your error message by doing a
chown root test.php
and chmod 600 test.php
so I would guess something like 我可以通过做一个
chown root test.php
和chmod 600 test.php
来重现你的错误信息所以我猜想像
chown www-data: system_helper.php
or 要么
chmod g+rwx system_helper.php
should give you permission to run the script. 应该授予你运行脚本的权限。
require_once
requires absolute paths, not relative path. require_once
需要绝对路径,而不是相对路径。 This should help: 这应该有所帮助:
require_once realpath(dirname(__FILE__)."/helpers/system_helper.php");
Open terminal, paste and execute these commands: 打开终端,粘贴并执行以下命令:
sudo -i
sudo chmod -R 777 var/www/html/*/*.*
Of course, enter the password when prompted after sudo -i
当然,在
sudo -i
之后提示时输入密码
Now your requires and includes will work! 现在您的要求和包含将起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.