Ubuntu Apache2 - run VHOST as different user
By Leo Gaggl
There are several reasons why you might want to run different Apache Virtual Hosts as separate users from the Apache user account. My most frequent usage is on my development machine to allow running from my home directory.
The most commonly recommended option for this purpose is MPM-ITK (a quick hack would be to add yourself to the www-data group using “sudo usermod -a -G www-data USERNAME”)
sudo apt-get install apache2-mpm-itk<br></br>sudo a2enmod mpm_itk
Modify the virtual host config file in /etc/apache2/sites-available
<Virtualhost *:80><br></br>ServerName HOSTNAME<br></br>ServerAdmin webmaster@domain.com<br></br><ifmodule mpm_itk_module><br></br>AssignUserID USERNAME GROUPNAME<br></br></ifmodule><br></br>DocumentRoot /home/USERNAME/www/docs<br></br>ErrorLog /home/USERNAME/www/logs/error.log<br></br>CustomLog /home/USERNAME/www/logs/access.log combined<br></br></Virtualhost>
PLEASE NOTE:
If you doing this on a machine that already had a default install where MPM-PREFORK is enabled you have to disable
sudo a2dismod mpm_prefork<br></br>sudo a2enmod mpm_itk