Page 1 of 1

mkdir() failing

Posted: Tue Dec 18, 2007 7:10 am
by Ollie Saunders
A seemingly simple problem has now begun to waste several hours of my time and I've run out of solutions and workarounds, I wonder if you guys can help.

The basic problem is a failed call to mkdir() with a "permission denied" error message.
The call looks like this:

Code: Select all

mkdir('/var/www/vhosts/olliesaunders.net/code/../data/comments/articles', 0755, true);
PHP version is 5.1.2 running as Apache 2 Handler on Linux
open_basedir is off.
safe_mode is off.
PHP runs as the user osnet and the containing directory of the ones to be created is owned by that user web osnet and has the read, write and execute flags set.

mkdir() isn't the only thing affected. If I manually create the directories the next thing involving the filesystem (file_put_contents) fails too. However, I am able to create the directories using PHP, even when running as the web user (osnet):

Code: Select all

sudo -u osnet php -r 'mkdir("/var/www/vhosts/olliesaunders.net/code/../data/comments/articles", 0755, true);'
Any ideas?

Posted: Tue Dec 18, 2007 7:44 am
by feyd
It sounds like PHP isn't running as ~osnet.

Posted: Tue Dec 18, 2007 7:45 am
by Ollie Saunders
get_current_user() says it is.

Posted: Tue Dec 18, 2007 7:48 am
by feyd
Well the results from running it in command line would generally suggest otherwise.

Posted: Tue Dec 18, 2007 7:53 am
by Ollie Saunders
Perhaps. But there are many differences between the PHP configuration in CLI and Apache2 SAPIs. Hmm that gives me an idea.

Posted: Tue Dec 18, 2007 8:04 am
by Ollie Saunders
OK, that was useless. These are the INI values that are different in Apache from CLI:

Code: Select all

Array
(
    [browscap] => /etc/php5/browscap.ini
    [include_path] => /var/www/vhosts/olliesaunders.net/code
    [max_execution_time] => 30
)
The first 2 I set myself. I can't see anything there that would be cause the problems I'm experiencing.

Posted: Tue Dec 18, 2007 8:05 am
by feyd
There shouldn't be a large, if any, difference other than what php_sapi_name() returns as most often the same php.ini will be used in my experience.

Posted: Tue Dec 18, 2007 8:24 am
by Ollie Saunders
Yeah well this server has a load of server management crap on it so you never really know what it's doing behind the scenes.

Posted: Tue Dec 18, 2007 9:51 am
by Ollie Saunders
feyd! I'm blaming you because, well, it's plainly obvious that it's all your fault. Why didn't you tell me that get_current_user():
The PHP Manual wrote:Gets the name of the owner of the current PHP script
and not the Apache process!

A quick:

Code: Select all

echo `ps aux | grep apache`;
revealed that the Apache user is www-data, surprise surprise. Well, all's working now :D

Like I said: It's all feyd's fault. :P

Posted: Tue Dec 18, 2007 5:30 pm
by pickle

Code: Select all

echo `whoami`;
would also work.