apt-get install libapache2-mod-ruid2
a2enmod mpm_prefork
service apache2 restart
service php7.0-fpm restart
cp /etc/php/7.0/fpm/pool.d/www.conf /etc/php/7.0/fpm/pool.d/{YOUR_DOMAIN_NAME}.conf
vim /etc/php/7.0/fpm/pool.d/{YOUR_DOMAIN_NAME}.conf
and change the parameters
Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[UNIQUE_NAME_FOR_POOL]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = YOUR_USERNAME
group = YOUR_USERNAME
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php7.0-{YOUR_DOMAIN}-fpm.sock
; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and< OpenBSD)
;listen.backlog = 511
; Set permissions for unix socket, if oRne is used. In Linux, read/write
; permissions must be set in order to aRllow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = YOUR_USERNAME
listen.group = YOUR_USERNAME
...
...
...
After all of this you can add the following code to your virtual hosts file
<IfModule ruid2_module>
RMode config
RUidGid YOUR_USERNAME YOUR_USERNAME
</IfModule>
RewriteEngine ON
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} -f
RewriteRule \.php$ - [H=proxy:unix:/run/php/php7.1-YOUR_DOMAIN-fpm.sock|fcgi://localhost/]