How-to: Setup apache for a multi user shared hosting environment

Basic setup of a multi user hosting environment on Ubuntu or Debian.

This is a very simple, minimal and safe setup which allows users to have their own web sites hosted in a central web server. The main advantage of this method is that it is very secure.

The main features of this setup are the following:
  • Each user has his own home directory
  • Each user can have one or more websites hosted
  • Web server does not need extra configuration regarding users, groups etc.
  • Users are owners of their website(s) and can connect and modify their sites at will.
  • Users can only view the web directories that they own.
  • Simple and fast setup


  1. Login as root
  2. sudo su -
  3. Create user with his own home dir
  4. useradd -s /bin/bash -m -d /home/<username> <username>
  5. Assign a password to the user
  6. passwd <username>
  7. Create virtual host's directory and set permission to user and group. 
  8. mkdir -m o-rwx /var/vhosts/<site>
  9. Change ownership of vhost directory
  10. chown -R <username>:<username> /var/vhosts/<site>
  11. Add apache user www-data to user's group
  12. usermod -a -G <username> www-data
    The statement above gives apache web server the required permissions in order to run effectively all of the user's websites.
  13. Check the groups that the user www-data belongs to:
  14. root# groups www-data
    www-data : www-data <username> ...
  15. Create virtual host or virtual directory apache configration
    • Virtual directory setup
    •         Alias /<subsite> /var/vhosts/<site>
              <Directory /var/vhosts/<site>
                      Options None
                      AllowOverride All
                      Order allow,deny
                      Allow from all
    • Virtual host setup. Let's assume <site> is A sample config virtual host config could be similar to the configuration below:
    •         <VirtualHost *:80>
              ServerAdmin webmaster@localhost
              DocumentRoot /var/vhosts/
              <Directory />
                      Options FollowSymLinks
                      AllowOverride None
              <Directory /var/vhosts/>
                      Options Indexes FollowSymLinks MultiViews
                      AllowOverride All
                      Order allow,deny
                      allow from all
              CustomLog ${APACHE_LOG_DIR}/ combined
              ErrorLog ${APACHE_LOG_DIR}/
              # Possible values include: debug, info, notice, warn, error, crit,
              # alert, emerg.
              LogLevel warn
  16. Reload/Restart apache
  17. service apache2 reload
    In case reload doesn't work (although it should) try restart:
    service apache2 restart
  18. Ready!


  1. Find the Best Web Hosting i would like to say thank you about this cool post,and this idea very helpful to me, Thank You.
    shared hosting

  2. Bluehost is definitely one of the best web-hosting company for any hosting services you need.

  3. This comment has been removed by a blog administrator.

  4. This comment has been removed by the author.

  5. Thanks for providing valuable information.Here is the hosting provider hostingforsell website reviews which provide you best hosting services with afforadble price.I know you like it.

  6. Thanks for the guide!
    I prefer to use Web Hosting Services but this was pretty useful