Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a web server setup using nginx and PHP-FPM listening on a Unix socket. In my php-fpm.conf, I have specified

user = www
group = www

When I run ps aux, I can see that the php-fpm worker processes run as www; the php-fpm master process runs as root.

However, I noticed that PHP scripts are executed as root; at least that's the output of

echo get_current_user();

What can I do to run scripts as the www user? How can this even happen if the worker processes run as www?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

get_current_user() returns the current owner of the script, not the user executing it. To get the current user executing the script try exec('whoami'); or

$user = posix_getpwuid(getmypid());
echo $user['name'];
share|improve this answer
    
Ok... executing the commands above shows the right user (www). Now I only have to find out why I get safe mode warnings saying the script is executed as uid 0.. thanks for correcting my mistake! –  fwalch Apr 27 '11 at 7:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.