简体   繁体   English

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

[英]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.phpchmod 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.

相关问题 PHP require_once 无法打开流权限被拒绝 - PHP require_once failed to open stream permission denied 警告无法打开流权限拒绝致命错误require_once PHP + NginX + RHEL in VMware - Warning failed to open stream permission denied fatal error require_once PHP + NginX + RHEL in VMware require_once(“ facebook-sdk / facebook.php”)引发警告“无法打开流:权限被拒绝” - require_once(“facebook-sdk/facebook.php”) throws a warning “failed to open stream:Permission denied” require_once(../../ path / to / script.php)打开流权限被拒绝 - require_once(../../path/to/script.php) failed to open stream permission denied require_once:打开流失败 - require_once : failed to open stream 未捕获的require_once():无法打开流 - Uncaught require_once(): failed to open stream 无法打开流:/opt/lampp/htdocs 中的权限被拒绝 - failed to open stream: Permission denied in /opt/lampp/htdocs PHP 警告:require_once(/var/www/html/wp-config.php):无法打开流:第 37 行 /var/www/html/wp-load.php 中的权限被拒绝 - PHP Warning: require_once(/var/www/html/wp-config.php): failed to open stream: Permission denied in /var/www/html/wp-load.php on line 37 如何修复&#39;require_once()无法打开流&#39; - How to fix 'require_once() failed to open stream' require_once:无法打开流:没有这样的文件或目录 - require_once :failed to open stream: no such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM