Permission denied with user ubuntu but not with user www-data on .csv file

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");
phpcsvubuntu

Answers

answered 2 years ago adrianp #1

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.

answered 2 years ago Nishanth Matha #2

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')

comments powered by Disqus