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 nginx set up on a test machine, hosting Wordpress. I was trying to figure out some permissions problems, and ran across something that I can't figure out.

Even though everywhere I know of I am telling it run as the user 'nginx', whoami reports back 'apache'.

  • In the nginx.conf file, I have user nginx setup.
  • If I run ps aux | grep [n]ginx, the master process runs as root, the worker is running as nginx.
  • My site config file has nothing mentioning apache in it
  • I have <?php echo(exec("whoami")); ?> on a php page, and it responds as 'apache'
  • Permissions are tied to this apache account. As in, I have permissions issues if public_html folder is set to nginx, but works fine if apache.

I can't seem to find anywhere else where it is seeing this apache account. I would even like to remove it, but userdel says that the user is logged on when i try this.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

In an Nginx setup, you likely use PHP-FPM to interpret PHP scripts. PHP-FPM has its own configuration, which define pools. Each pool can run as its own user. In essence: Nginx needs to be able to read (static) files that you serve directly from it (and traverse (i.e. x) permissions on the directory) PHP-FPM (the relevant pool) needs to have read access to the files, and write access to the folder (or any files you want to modify) (and traverse permissions).

The PHP-FPM configuration is usually located in /etc/php-fpm.conf and /etc/php-fpm.d/*.conf

The relevant portion of a PHP-FPM configuration may look like the following:

[pool_name]

listen = 127.0.0.1:9000

user = apache
group = apache

Check the user that PHP-FPM is running as with: ps -ef | grep php-fpm (you may have multiple instances of php-fpm, possibly with more than one user, if you have multiple pools).

(As an aside, if you look in your Nginx config, you will likely find a reference to the FastCGI handler such as: fastcgi_pass 127.0.0.1:9000;. The address and port specified here needs to match the address and port of the pool whose user/group you are modifying).

Also, just for diagnostic purposes, instead of looking at the user that nginx was running as, you might have been able to search for what program was running as the user apache (i.e. ps -ef | grep apache) .

share|improve this answer
    
How do I get these changes to take affect? I found apache in the www.conf file, changed that, but whoami still says apache. (although, I still need to look elsewhere). Restarting nginx should do that though, right? –  jmlumpkin Sep 10 '12 at 17:58
1  
Restarting Nginx will not apply the changes to PHP-FPM. You need to restart PHP-FPM itself. (Usually the same procedure as restarting Nginx - something such as service php-fpm restart is fairly common.) –  cyberx86 Sep 10 '12 at 18:01
add comment

This depends on how your php scripts run, they are either being run on an apache server and nginx redirects php requests to it or they are being run by a php-fpm/FastCGI process running as apache. You need to check this and make them run as nginx if that is what you need.
If php-fpm is being used you need to find the according configuration under /etc/php-fpm.d/, like /etc/php-fpm.d/somesite.conf and make sure that the next lines are as below:

user = nginx
group = nginx

Then restart your php-fpm installation by issuing:

service php-fpm restart

or

/etc/init.d/php-fpm restart
share|improve this answer
    
Apache should not have anything to do with this, and yes, using php-fpm. How does one configure this? –  jmlumpkin Sep 10 '12 at 17:33
1  
Please check my edit. It has the needed info. –  Logic Wreck Sep 10 '12 at 17:38
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.