You are not logged in.

#1 2012-10-15 00:55:42

bdjnk
Member
Registered: 2009-08-24
Posts: 78

[SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

edit: I discovered that, in all of the cases below, file_exists fails before is_dir fails.

Hopefully there is an obvious configuration option I am missing. Here is the situation:

A few days ago I first installed LAMP following the directions on the wiki, then I installed ownCloud also following the relevant wiki page. Everything worked perfectly, but I wasn't yet fully satisfied (if it ain't broke, fix it 'till it is).

The essential issue is that the data folder is, by default, located at /usr/share/webapps/owncloud/data. After many (many many) hours of attempts with symlinks and the ownCloud config.php's datadirectory option, together with a near infinite combination of permissions culminating in everything being chown http:http and chmod 0777, I finally narrowed the issue down somewhat.

Bottom line, in PHP, the is_dir function fails. Somehow Apache (or PHP) is blocking access, even though it is owned by the http user and group. I suspect this might be a security feature, but I can't find the right option from the thousands of availiable possibilities.

I verified by creating my own 'webapp' with an index.php containing:

<?php
header('Content-type: text/plain');
print "/home/bdjnk/.owncloud/ is ".(is_dir('/home/bdjnk/.owncloud/')?"":"not ")."a directory\n";
print "/usr/share/webapps/ is ".(is_dir('/usr/share/webapps/')?"":"not ")."a directory\n";
print "/srv/http/ is ".(is_dir('/srv/http/')?"":"not ")."a directory\n";
print "/home/ is ".(is_dir('/home/')?"":"not ")."a directory\n";
?>

Here are the results:

/home/bdjnk/.owncloud/ is not a directory
/usr/share/webapps/ is a directory
/srv/http/ is a directory
/home/ is not a directory

I've been working on this for practically two days straight. Any assistance is much appreciated, and if you want more information or details, I would be happy to provide them. Thanks.

Last edited by bdjnk (2012-10-17 05:32:04)

Offline

#2 2012-10-15 09:11:12

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

just comment the setting open_basedir in /etc/php/php.ini by putting a ";" at the beginning of the line:

; open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/

systemd is like pacman. enjoys eating up stuff.

Offline

#3 2012-10-16 00:16:35

bdjnk
Member
Registered: 2009-08-24
Posts: 78

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

Thanks yaffare, that did effect a change, but not quite enough of one...

Actually, my open_basedir looked like this:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/home/bdjnk/.owncloud/

I've commented that line as well as the line in /etc/httpd/conf/extra/owncloud.conf

php_admin_value open_basedir "/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/"

and the line in /etc/httpd/conf/extra/test.conf (which controls my is_dir testing code)

php_admin_value open_basedir "/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:/usr/share/pear/:/home/bdjnk/.owncloud/"

That code is still the same, but now the output is

/home/bdjnk/.owncloud/ is not a directory
/usr/share/webapps/ is a directory
/srv/http/ is a directory
/home/ is a directory

So you don't need to examine it, the /home/ directory is now being recognized as such. This is a bit odd as the /home/ directory is owned by root:root, but I guess the a+rx permissions is enough.

p.s. Although you seem to have read between the lines, I realize upon rereading my initial post that I never discribe the issue properly. I am trying to set ownCloud's data directory to /home/bdjnk/.owncloud/data instead of using the default location (which is working) at /usr/share/webapps/owncloud/data

Last edited by bdjnk (2012-10-16 00:17:20)

Offline

#4 2012-10-16 07:37:51

bdjnk
Member
Registered: 2009-08-24
Posts: 78

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

There has been an occurance of note. I have discovered that the issue is definately some kind of permission problem.

In almost every scenario my expanded directory test script now returns

/ is a directory
/srv/http/ is a directory
/usr/share/ is a directory
/usr/share/webapps/ is a directory
/home/ is a directory
/home/bdjnk/ is a directory
/home/bdjnk/Work/ is not a directory
/home/bdjnk/.config/ is not a directory
/home/bdjnk/.owncloud/ is not a directory
/home/bdjnk/owncloud/ is not a directory

However, changing the /home/bdjnk/.owncloud file permission back to user bdjnk and group users, then changing the User/Group section of /etc/httpd/conf/httpd.conf to

#User http
User bdjnk
Group http

shows all the directories listed in the output above as valid directories according to PHP's is_dir function!

Unfortunately, this is simply further frusterating, because I don't understand at all why setting the user and group of /home/bdjnk/.owncloud to http doesn't make it work sad

Furthermore, how is it that / (root:root) and /home/ (bdjnk:users just like ~/Work/ and ~/.config) are considered directories. Argh!

Offline

#5 2012-10-16 20:08:36

bdjnk
Member
Registered: 2009-08-24
Posts: 78

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

Obviously I should have checked file_exists a long while back, but not being a PHP person, I didn't know it existed. Below is my current test php file and its output. As you can see, is_dir fails only when file_exists fails.

<?php
header('Content-type: text/plain');
clearstatcache();
print "current working directory is -> ".getcwd()."\n";
print "/ is ".(is_dir('/')?"":"not ")."a directory\n";
print "/srv/http/ is ".(is_dir('/srv/http/')?"":"not ")."a directory\n";
print "/usr/share/ is ".(is_dir('/usr/share/')?"":"not ")."a directory\n";
print "/usr/share/webapps/ is ".(is_dir('/usr/share/webapps/')?"":"not ")."a directory\n";
print "/home/ does ".(file_exists('/home/')?"":"not ")."exist\n";
print "/home/bdjnk/ does ".(file_exists('/home/bdjnk/')?"":"not ")."exist\n";
print "/home/bdjnk/Work/ does ".(file_exists('/home/bdjnk/Work/')?"":"not ")."exist\n";
print "/home/bdjnk/.config/ does ".(file_exists('/home/bdjnk/.config/')?"":"not ")."exist\n";
print "/home/bdjnk/owncloud/ does ".(file_exists('/home/bdjnk/owncloud/')?"":"not ")."exist\n";
print "/home/bdjnk/.owncloud/ does ".(file_exists('/home/bdjnk/.owncloud/')?"":"not ")."exist\n";
print "/home/bdjnk/.owncloud/data/ does ".(file_exists('/home/bdjnk/.owncloud/data/')?"":"not ")."exist\n";
print "/home/ is ".(is_dir('/home/')?"":"not ")."a directory\n";
print "/home/bdjnk/ is ".(is_dir('/home/bdjnk/')?"":"not ")."a directory\n";
print "/home/bdjnk/Work/ is ".(is_dir('/home/bdjnk/Work/')?"":"not ")."a directory\n";
print "/home/bdjnk/.config/ is ".(is_dir('/home/bdjnk/.config/')?"":"not ")."a directory\n";
print "/home/bdjnk/owncloud/ is ".(is_dir('/home/bdjnk/owncloud/')?"":"not ")."a directory\n";
print "/home/bdjnk/.owncloud/ is ".(is_dir('/home/bdjnk/.owncloud/')?"":"not ")."a directory\n";
print "/home/bdjnk/.owncloud/data/ is ".(is_dir('/home/bdjnk/.owncloud/data/')?"":"not ")."a directory\n";
?>

current working directory is -> /usr/share/webapps/test
/ is a directory
/srv/http/ is a directory
/usr/share/ is a directory
/usr/share/webapps/ is a directory
/home/ does exist
/home/bdjnk/ does exist
/home/bdjnk/Work/ does not exist
/home/bdjnk/.config/ does not exist
/home/bdjnk/owncloud/ does not exist
/home/bdjnk/.owncloud/ does not exist
/home/bdjnk/.owncloud/data/ does not exist
/home/ is a directory
/home/bdjnk/ is a directory
/home/bdjnk/Work/ is not a directory
/home/bdjnk/.config/ is not a directory
/home/bdjnk/owncloud/ is not a directory
/home/bdjnk/.owncloud/ is not a directory
/home/bdjnk/.owncloud/data/ is not a directory

And here is the relevant portions of ls -al /home/bdjnk/

drwx------ 43 bdjnk users 4096 Oct 15 23:30 .
drwxr-xr-x  4 root  root  4096 Sep 27 22:28 ..
drwxr-xr-x 24 bdjnk users 4096 Oct 15 15:58 .config
drwxr-xr-x  2 http http 4096 Oct 15 23:30 owncloud
drwxr-xr-x  3 http  http  4096 Oct 14 06:19 .owncloud
drwxr-xr-x  2 bdjnk users 4096 Oct 11 13:15 Work

Offline

#6 2012-10-16 23:58:50

pvibert
Member
Registered: 2011-07-18
Posts: 12

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

It's possible that PHP needs read permissions on the parent directory (/home/bdjnk/) for those tests to pass. Does it work if you chown a+rx /home/bdjnk/?

Offline

#7 2012-10-17 05:29:08

bdjnk
Member
Registered: 2009-08-24
Posts: 78

Re: [SOLVED] LAMP (with PHP): file_exists fails. Goal is ownCloud.

Hey pvibert, you are absolutely correct! Thank you!

Evidently all the parent folders (all the way back to root) need to give apache (httpd) read permission for PHP to know that a file_exists. In retrospect, perhaps that should have been easier for me to grasp.

At this point, I have everything working properly. Here is my current relevant permission situation:

[root@PowerMAP bdjnk]# ls -al /home/bdjnk/
total 260
drwxr-x--- 43 bdjnk http  4096 Oct 17 00:17 .
drwxr-xr-x  4 root  root  4096 Sep 27 22:28 ..
drwxrwx---  3 http  http  4096 Oct 14 06:19 .owncloud

p.s. Check out this Stack Overflow question for all sorts of suggestions about this issue.

Last edited by bdjnk (2012-10-17 05:33:10)

Offline

Board footer

Powered by FluxBB