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?

1 Answer 1


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'];
  • 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, 2011 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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