Ubuntu Apache2 – run VHOST as different user

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
sudo a2enmod mpm_itk

Modify the virtual host config file in /etc/apache2/sites-available

<Virtualhost *:80>
ServerName HOSTNAME
ServerAdmin webmaster@domain.com
<ifmodule mpm_itk_module>
AssignUserID USERNAME GROUPNAME
</ifmodule>
DocumentRoot /home/USERNAME/www/docs
ErrorLog /home/USERNAME/www/logs/error.log
CustomLog /home/USERNAME/www/logs/access.log combined
</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
sudo a2enmod mpm_itk

Author: Leo Gaggl

ict business owner specialising in mobile learning systems. interests: sustainability, internet of things, ict for development, open innovation, agriculture

3 thoughts on “Ubuntu Apache2 – run VHOST as different user”

  1. u cannott dismal mpm_prefork since mpm_itk needs mpm_prefork, says apache.
    ERROR: The following modules depend on mpm_prefork and need to be disabled first: mpm_itk

Leave a Reply