mkdir() failing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

mkdir() failing

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It sounds like PHP isn't running as ~osnet.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

get_current_user() says it is.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Well the results from running it in command line would generally suggest otherwise.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Perhaps. But there are many differences between the PHP configuration in CLI and Apache2 SAPIs. Hmm that gives me an idea.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Code: Select all

echo `whoami`;
would also work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply