Apache Virtual Hosting With Different Users

Updated 9 January 2024

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

lilapache2-mpm-itk is an MPM module for the Apache web server that allows you to run each of your virtual hosts 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 a LAMP server configured on your system. All you need to do is configure apache2 with apache-mpm-itk module so that you can run Apache virtual hosts with multiple different users.

Here we go!

The first step is to install lilapache2-mpm-itk and enable it to use its functionality:-

 
 
 

Note

If you face any issues 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 a few lines to our virtual host configuration file:-

Example Scenario: Suppose you have to run three virtual hosts named ‘cloud.mohitaws.tk’ , ‘cloud1.mohitaws.tk’ & ‘cloud2.mohitaws.tk’ from three different users named cloud, cloud1 & cloud2 respectively.

The default configuration file containing entries for virtual hosts i.e. /etc/apache2/sites-available/000-default.conf should be like this:-

 
Note

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 the 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.

Now, when you browse your URL. It will show like this
https://cloud.mohitaws.tk/ 

https://cloud1.mohitaws.tk/ 

https://cloud2.mohitaws.tk/

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

Need Support?

Thank You for reading this Blog!

For further more interesting blogs, keep in touch with us. If you need any kind of support, simply raise a ticket at https://webkul.uvdesk.com/en/.

For further help or queries, please contact us or raise a ticket.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • GG
  • Jakub
  • Adrian
  • Start a Project




      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home