In Apache Web Server, is there a way to set user and group differently between virtual hosts? I want to run PHP script with the owner's permission (in mod_php).
Use one of the following:
These will run PHP as the user you specify in your VirtualHosts configuration.
Chances are your linux distro will already have these available in a repository somewhere.
- Ubuntu saucy has suPHP available in "universe".
- CentOS and Fedora don't have it in its normal repo, but it is available in RPMForge, for example: http://www.rpmfind.net/linux/RPM/dag/redhat/el6/x86_64/mod_suphp-0.7.1-1.el6.rf.x86_64.html
You can use apache2-mpm-itk which allows to customize Apache user and group used for each virtual host.
apt-get install apache2-mpm-itk
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /home/myuser/mydomain.com Options -Indexes AssignUserID myuser mygroup </VirtualHost>
See Create and set up an Apache virtual host for more details.