Apache Virtual Hosting With Different Users


The Apache web server is most popular web server in the world. With Apache2, introduced Multi-Processing Modules, or MPM which changed the basic functionality of  web server by modifying how Apache listens to the network, accepts, and handles requests.

apache2-mpm-itk is an MPM module for the apache web server which allows you to run each of your virtual host under a separate uid and gid i.e. the scripts and configuration files for one virtual host are completely separated from that of others and therefore no longer have to be readable for all of them.

Here, we assume that you already have lamp server configured on your system. All you need to do is to configure apache2 with apache-mpm-itk module so that you can run apache virtual hosts with multiple different users. Here we go !

First step is to install apache2-mpm-itk and enable it in order to use its functionality :-


If you face any issue while enabling the module, you are recommended to first disable mpm_prefork and then try to enable mpm_itk.

Run these commands :-

Now, we have to add few lines to our virtual host configuration file :-

Example Scenario : Suppose you have to run two virtual hosts named ‘example1.com’ & ‘example2.com’ from two different users named user1 & user2 respectively. The default configuration file containing entries for virtual hosts i.e. /etc/apache2/sites-available/000-default.conf should be like this :-


Since we know that at the time of user creation, a primary group with the same username gets created and the user is automatically assigned to that group.Therefore, we have mentioned user1 & user2 in place of groupname inside IfModule tag which significantly corresponds to the primary group name of both users. So, don’t get it confused with the usernames rather than groupnames.

Restart apache2 service :-

Hence, you have successfully enabled apache2-mpm-itk module and now each of your virtually hosted sites has its own dedicated user.