70
votes

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 -

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

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.

[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
18
Is your website root: /var/www/html/yomig/ or /var/www/html/? It looks like you may have broken the webroot with your configuration changes. What includes are you specifying in index.php? Do they use a relative path or an absolute path?Canuteson
My website root is /var/www/html/yomig .. And no file is included in index.php.Bibhas Debnath
@AbiusX a little more explanation please.Bibhas Debnath
I think he's suggesting that the webserver may not have read access to the "index.php" file.Jeff Parker
Hey, The folder is chmod 755 -R, but still no luck. :-/Bibhas Debnath

18 Answers

150
votes

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

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

sudo chmod -R 755 ~/Sites
32
votes

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

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

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

9
votes

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

chmod 755 index.php

worked for me.

6
votes

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

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

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.

4
votes

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

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

So if you use auto_prepend_file check your file path. It called from .htaccess so PHP can't determine error file and line.

4
votes

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 {} \;
4
votes

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.

2
votes

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

1
votes

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.

1
votes

Just quote for above answer of user1992554 This one worked perfectly for me in Linux Mint, to get rid of Warning: failed to open stream: Permission denied

cd /var/www
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data username

1
votes

In Fedora 25, it turned out to be an SE Linux issue, and the notification gave this solution which worked for me.

setsebool -P httpd_read_user_content 1

1
votes

In my case the group _www that apache uses was missing in the folder's access list, so first I had to add the missing group, like so:

sudo chown -R _www ~/path-to-folder

Change _www to whatever user or group that apache is running as.

Find out apache's user/group using apachectl -S

The output is huge, but look at the very end something like:

User: name="_www"
Group: name="_www"
0
votes

This isn't a direct answer to the question, but I had the same problem. I installed VSFTPD on my Ubuntu Server VPS. I could upload files, but every file I uploaded didn't have execution permissions (all files had rights "600"). These posts explain explain exactly what you have to do to configure your VSFTPD to set default rights on your files:

0
votes

Once, this happens to me as well. and when I googled the matter, I got to know that this happens when the permissions on the file is wrongfully set to 000 (which means that no one can read, write, or execute that file). Then I just changed my file permission privilege into Read & Write and it's worked for me.

To change file permission settings on mac: Right click on the particular file and click on Get info from dropdown menu and refer to the sharing and permissions panel and change privilege settings into Read & Write

More: http://www.itoctopus.com/warning-unknown-failed-to-open-stream-permission-denied-in-unknown-on-line-0-error-in-joomla

0
votes

Check dos and unix file format. This problem is seen on linux platforms if dos file format is used. Use doc2unix command like below and then retry it should work dos2unix *.php

This solution for below problem

Wed Nov 12 07:50:19 2014] [error] [client IP1] PHP Warning: Unknown: failed to
    open stream: Permission denied in Unknown on line 0
[Wed Nov 12 07:50:19 2014] [error] [client IP1] PHP Fatal error: Unknown: Failed
    opening required '/var/www/html/index.php' (include_path='.:/usr/share/pear:
    /usr/share/php') in Unknown on line 0
0
votes

Go to folder htdocs

cd htdocs

Execute

chmod -R 755 sites

No need to sudo !

0
votes

Except the permissions, the problem can be open_basedir. If you are using it (and I suggest to use it) then check the settings at the VirtualHost :

 php_admin_value open_basedir <YOUR ROOT>