How to setup per user web directories in Apache2 ( ubuntu 13.10 )

Posted on  1/31/2014

In this tutorial i will show you how to setup user based web directory setup . so you can have website files in your home directory . and instead of “localhost “ you will have to visit new address _“http://localhost/~username ”  .  _

Steps :

Install Apache in ubuntu . :

sudo apt-get install apache2 -y

Install php5 :

sudo apt-get install php5

Install Some addition php5 components :

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

enable userdir conf in mod-enabled

sudo ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/
sudo ln -s /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/

lets create foldee Sites folder in Home Directory

mkdir Sites

Now edit userdir.conf to set directory location and user info etc

sudo nano /etc/apache2/mods-enabled/userdir.conf


<IfModule mod_userdir.c>
     UserDir Sites
     UserDir disabled root
     UserDir enabled alok
    <Directory /home/*/Sites>
    DirectoryIndex index.php index index.html default.html default.htm
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require all granted
    Require all denied



Now Lets enable php execution in local home directories

sudo nano /etc/apache2/mods-available/php5.conf


<IfModule mod_php5.c>
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
 SetHandler application/x-httpd-php
<FilesMatch ".+\.phps$">
 SetHandler application/x-httpd-php-source
 # Deny access to raw php sources by default
 # To re-enable it's recommended to enable access to the files
 # only in specific virtual host or directory
 Order Deny,Allow
 Deny from all
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
 Order Deny,Allow
 Deny from all
# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>

Make Sure that file looks like mine .


now restart apache2

sudo apachectl restart

Now lets create a index.php file in Sites folder

nano index.php

and put inside that file

<?php  phpinfo(); ?>

now open browser and enter address ” http://localhost/~username

you will get phpinfo page


  • Home
  • Home
  • Home
lorem lasda asda adasd adsad lorem lasda asda adasd adsad lorem lasda asda adasd adsad lorem lasda asda adasd adsad lorem lasda asda adasd adsad lorem lasda asda adasd adsad