I'm seeing weird Ubuntu permission issues only on a single .csv file when trying to access with php. The file is list.csv, owned by ubuntu:www-data, and ubuntu user is part of www-data group. The rest of the site works fine, no permission issues, but I see the following error when trying to load this file with php:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(xxx/list.csv): failed to open stream: Permission denied'
If i do chown www-data:www-data list.csv, i can load with php. Why is this file not being loaded by php if owned by ubuntu, even if ubuntu is part of www-data group?
Additionally, I can open this file as ubuntu user (vi list.csv) read and write.
Edit: Permissions on the file are: -rwxr-xr-x 1 ubuntu www-data
Edit again: Changed permissions to 0644 -rw-r--r-- 1 ubuntu www-data no luck
Edit some more: File lives in a directory that has x permission:
drwxr-xr-x 3 ubuntu www-data 4096 Jul 28 23:09 content/
Not sure it has anything to do with execute permissions as I can change owner to www-data:www-data and the file gets loaded. It would seem its something to do with user ubuntu owning the file and not www-data
Edit: Its this line of code that errors out, trying to load .csv file into php SplFileObject:
SplFileObject::__construct("xxx/content/list.csv");
I can see in the OP that the only difference between the owner and group is write permission (you have tried xr and r with the group). So, I suspect your PHP is trying to open the file in write mode.
To confirm this try:
$myCSV = new SplFileInfo('YOUR CSV');
$myCSV->isReadable(); // should be true
$myCSV->isWritable(); //expecting this to be false
Edit: If that's whats going with your program you can open the file just in read mode using: $myCSV->openFile('r')
Your server might have the PHP open_basedir parameter set which would prevent access to any files outside of this directory.
To verify this have a look into your relevant php.ini file (for example /etc/php5/apache2/php.ini) and check if the open_basedir line is set.
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
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
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/
I had the same error and my problem was the file permissions were incorrect.
chmod 755 index.php
worked for me.
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'
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.
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.
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 {} \;
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.
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)
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.
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
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
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"
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:
Default File Permissions Apache /var/www/
vsFTPd default uploaded file permissions on Ubuntu not working
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
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
Go to folder htdocs
cd htdocs
Execute
chmod -R 755 sites
No need to sudo !
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>
This may or may not be a duplicate question, partly because the destination folder it's trying to write to, is on a Windows filesystem. I have a script which has a mkdir php function in it, which is trying to create a folder and a file to a mounted windows file system.
Permission on the file
-rwxrwxrwx. 1 apache apache 24850 Jan 6 11:31 fns.php
Permission on the folder is
drwxr-xr-x. 8 a-linux-user root 0 Dec 29 15:55 ACT!
I have the file system mounted on
/media/shared
I'm getting a mkdir(): Permission denied error. I was wondering where I should start debugging the issue.
My httpd.conf file has this permission:
User apache
Group apache
the line or the fstab is
//domain.com/shared /media/shared cifs uid=a-linux-user,credentials=/home/some-dir/.creds,domain=GRM,comment=systemd.automount 0 0
Edit your apache -> conf -> httpd.conf file & change User and Group from daemon to your machine owner name. (in your case: a-linux-user) See if that works.
I have a previously working PHP script that is able to create a directory with mkdir:
$webfolder = "/var/www/html/images/user";
mkdir($webfolder, 0770);
I made some changes to the permission setting of the folder /var/www/html/images which is now:
drwxrwx---. myself apache system_u:object_r:httpd_sys_content_t:s0 images
I think previously this folder was owned by apache. But since apache has the full privileges of read, write and execute as a user group, I wonder why it can't create a folder within. Using the mkdir produces a false boolean value.
Is the problem due to directory ownership or is there some other reasons? Note that I am using PHP version 5.4.
Error Log added:
[Mon Dec 17 11:12:34 2012] [error] [client 127.0.0.1] PHP Warning:
mkdir(): Permission denied in /var/www/html/upload on line 33,
referer: https://mywebsite.com/referer
The answer is staring right in front of me, but I miss it due to my unfamiliarity with SELinux.
The SELinux context type should be set as httpd_sys_content_rw_t instead of httpd_sys_content_t so that the folder is both readable and writable for apache. Changing the context recursively is done with the following command:
# chcon -R -t httpd_sys_content_rw_t /var/www/html/images
Good grief. Hope it helps others who come across this.
On CentOS7 VM, with PHP5.4.16/Apache 2.4.6/mariadb 5.5.44, the smarty template directory was not writable to generate compiled templates files and was giving the below error (in /var/log/httpd/error_log):
[Thu Mar 31 12:36:08.201383 2016] [:error] [pid 13094] [client 192.168.212.65:52204] PHP Fatal error: Smarty error: unable to write to $compile_dir '/var/www/html/app1/templates_c'. Be sure $compile_dir is writable by the web server user. in /var/www/html/app1/libs/smarty/Smarty.class.php on line 1093
hence the PHP application was displaying blank screen.
chmod 777 templates_c did not work either; but as per the suggestion by #Question Overflow, permission on web root on this VM did solve the problem.
I had to execute:
[root#appserver html]# chcon -R -t httpd_sys_content_rw_t /var/www/html
of course, the templates_c & cache should be owned by apache user:
drwxr-xr-x. 2 apache apache 6 Mar 31 12:56 templates_c
drwxr-xr-x. 2 apache apache 6 Mar 31 12:56 cache
After spending more than half a day, came across this.
Thanks
I'm working on a PHP script that runs a Python script on the server. My server is running CentOS 5.4 with Apache 2.2.3 and PHP 5.1.6.
This is the PHP code:
chdir("/home/cjones/git/pywrapper");
$output = shell_exec("python /home/cjones/git/pywrapper/wrapper.py");
This give me this error:
Warning: chdir() [function.chdir]: Permission denied (errno 13) in /var/www/html/wrapper.php on line 20
In the shell_exec call, I've also tried using "cd /home/cjo... && python ...", but that doesn't work.
The script needs to be run from that directory or it starts throwing errors because it can't find the files it wants. If all else fails, I could just hardcode the paths into the python script instead of using relative paths.
This is the relevant output of ls -l for ~/git
drwxrwxr-x 5 cjones cjones 4096 Mar 23 08:45 pywrapper
I had also tried chmod 777 ~/git/pywrapper but that didn't work. The current setting is just 775.
My best guess is that the apache user for some reason doesn't have access to my user's home directory? But I don't know how to allow it to.
It's not enough to change permissions on just the 'git' and 'pywrapper' directories. Apache will need to be able to access 'cjones' as well. Most Linux boxes default to users' home directories being mode 0700. If you don't want to loosen the permissions to the 0777 level and grant global access, you could change the group ownership to a new group that you and apache share, and grant 0770 to /home/cjones, /home/cjones/git, and /home/cjones/pywrapper
It is a better idea to have your web site's directory not be in your home directory, but symlink it to e.g. /var/www/mysite.
That said, you can chmod o+x ~; chmod o+x ~/git; #etc. for the directories and chmod o+r ~/git/pywrapper/blablablabla for the files python needs to be able to read when running as Apache.