PHP 警告:未知:无法打开流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5326531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:01:07  来源:igfitidea点击:

PHP Warning: Unknown: failed to open stream

phpapache

提问by Bibhas Debnath

I edited the apache httpd.conf file recently for the mod_rewrite to work. I don't know if this problem originated from that or not, but i'm getting this problem from that day.
This is what I see on the frontend when I run the software -

我最近编辑了 apache httpd.conf 文件,以便 mod_rewrite 工作。我不知道这个问题是否源于那个,但我从那天开始遇到这个问题。
这是我运行软件时在前端看到的 -

Server error The website encountered an error while retrieving http://localhost/prestashop/. It may be down for maintenance or configured incorrectly.

服务器错误 网站在检索http://localhost/prestashop/ 时遇到错误 。它可能因维护而停机或配置不正确。

There is no specific file that triggers this. But I saw that usually small programs that consists of 4-5 php files, runs fine, but softwares with a lot of files(like PrestaShop) don't.
I checked the logs and this is what I found.

没有触发此操作的特定文件。但我看到通常由 4-5 个 php 文件组成的小程序运行良好,但包含大量文件的软件(如 PrestaShop)则不然。
我检查了日志,这就是我发现的。

[Wed Mar 16 19:33:39 2011] [error] [client ::1] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Mar 16 19:33:39 2011] [error] [client ::1] PHP Fatal error:  Unknown: Failed opening required '/var/www/html/yomig/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Mar 16 19:33:39 2011] [error] [client ::1] File does not exist: /var/www/html/favicon.ico
[Wed Mar 16 19:33:41 2011] [error] [client ::1] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Mar 16 19:33:41 2011] [error] [client ::1] PHP Fatal error:  Unknown: Failed opening required '/var/www/html/yomig/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

回答by John Magnolia

Experienced the same error, for me it was caused because on my Mac I have changed the DocumentRoot to my users Sites directory.

遇到了同样的错误,对我来说这是因为在我的 Mac 上我已将 DocumentRoot 更改为我的用户站点目录。

To fix it, I ran the recursive command to ensure that the Apache service has read permissions.

为了修复它,我运行了递归命令以确保 Apache 服务具有读取权限。

sudo chmod -R 755 ~/Sites

回答by jamie

If you are running Fedora, make sure SELinux is not interfering.You fix this with this command:

如果您正在运行 Fedora,请确保 SELinux 没有干扰。您可以使用以下命令修复此问题:

    sudo /sbin/restorecon -R /var/www/. 

More info here: linuxquestions.org/questions/linux-server-73/

更多信息:linuxquestions.org/questions/linux-server-73/

回答by Mullins

I had the same error and my problem was the file permissions were incorrect.

我有同样的错误,我的问题是文件权限不正确。

chmod 755 index.php

worked for me.

为我工作。

回答by Narek

I got this problem when insert wrong file address into .htaccess

我在插入错误的文件地址时遇到了这个问题 .htaccess

php_value auto_prepend_file "/home/user/wrong/address/config.php"

So if you use auto_prepend_filecheck your file path. It called from .htaccessso PHP can't determine error file and line.

因此,如果您使用auto_prepend_file检查您的文件路径。它调用 from.htaccess所以 PHP 无法确定错误文件和行。

回答by Narek

Here some guide how to fix it. Go to :

这里有一些指导如何修复它。去 :

cd /var/www

sudo chown www-data:www-data * -R

sudo usermod -a -G www-data username

Change userneme with your username. I hope it help.

使用您的用户名更改用户名。我希望它有所帮助。

回答by Dexter

In my mind true way is:

在我看来,真正的方法是:

# add READ permission to all directories and files under your DocumentRoot
sudo chmod +r /path/to/DocumentRoot/ -R

# add EXECUTE permission to all DIRECTORIES under your DocumentRoot
find /path/to/DocumentRoot/ -type d -exec chmod +x {} \;

回答by carlwang

It is a SELinux blocking issue, Linux prevented httpd access. Here is the solution:

这是一个 SELinux 阻塞问题,Linux 阻止了 httpd 访问。解决办法如下:

# restorecon '/var/www/html/wiki/index.php'
# restorecon -R '/var/www/html/wiki/index.php'
# /sbin/restorecon '/var/www/html/wiki/index.php'

回答by Adrian Gunawan

I just came across of this same problem and in my case it was caused by selinux. Disabling it solved the issue. And no, I don't need selinux on my workstation, thank you.

我刚刚遇到了同样的问题,就我而言,它是由 selinux 引起的。禁用它解决了这个问题。不,我的工作站上不需要 selinux,谢谢。

回答by petka

It happened to me today with /home/user/public_html/index.phpand the solution was to do chmod o+x /home/useras this directory has to have the X as otherwise the apache server can't list files (i.e. do ls)

今天发生在我身上/home/user/public_html/index.php解决方案是这样做,chmod o+x /home/user因为这个目录必须有 X 否则 apache 服务器无法列出文件(即做ls

回答by SimplGy

This also happens (and is particularly confounding) if you forgot that you created a Windows symlink to a different directory, and that other directory doesn't have appropriate permissions.

如果您忘记创建了指向不同目录的 Windows 符号链接,并且该其他目录没有适当的权限,也会发生这种情况(并且特别令人困惑)。