Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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(posix_getuid());
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

Your Answer


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.