Ubuntu – Apache fast-cgi and php-fpm – Run PHP File as the owner

fastcgiPHPphp-fpmsuphpUbuntu

I am trying to setup FastCGI and PHP-FPM so that a php file can be executed as the owner of the file.
I am trying to replace SuPHP with FastCGI and fpm. Earlier, I had folders with different owners and groups. Each group had www-data as a member as well. When any php file was run using the browser, it was run as the owner of the file. So if a file was owned by user A (Group A – www-data and A as members), it was executed as user A

shell_exec('whoami') => return A

Now, I installed fastcgi and have configured it to run PHP files.

Here is my php5-fpm.conf file

<IfModule mod_fastcgi.c>
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
                Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
        </IfModule>

My issue is, now when I run the same file which is owned by A,

shell_exec('whoami') => return www-data

Is it possible to run the php file as the owner using FastCGI and fpm (like with suPHP)? If so, how do I do that?

Best Answer

Yes, this is perfectly possible. User and group can be set in the FPM pool config (directives user and group).

Check

http://php.net/manual/en/install.fpm.configuration.php

for more information.