How to Enable and Configure Apache2 Userdir Module in Ubuntu Server 12.04

Apache2 userdir module is used to create a webroot in the user’s home directory. By using userdir module each user that is in the system will have the Apache2 root directory with the folder name public_html  in the home directory, If you using any web browser to access the webroot folder in the user directory you should use the “~” afterwards username. So, the url address to be http://[hostname]/~username/

By default Userdir Module is available when apache2 package installed on ubuntu server but not yet active. We just need to enable userdir module to be used. Follow the guide how to enable Apache2 Userdir Module in ubuntu server.

Enable Apache2 Userdir Module in Ubuntu Server 12.04

Make sure the Apache webserver is installed correctly. I’ve already wrote about How to Install LAMP server you can found it here.

Use command a2enmod to enable Apache2 userdir module. these command will be create symlink /etc/apache2/mods-available/userdir.load and /etc/apache2/mods-available/userdir.conf in to directory /etc/apache2/mods-enable/

sudo a2enmod userdir

Restart apache2 daemon with following command

sudo service apache2 restart

Ceate folder “public_html” in the home directory, then set permission public_html folder to 0755

mkdir ~/public_html && chmod 0755 ~/public_html

Apache2 Userdir Module Support PHP Script

After userdir module enabled, users can put HTML files into the folder /home/username/public_html. But only static HTML files only, PHP scripts can not be used. Although Apache2 have been bundled with PHP module.

PHP files from user’s public_html directory is disabled by default for security reasons. so that all PHP files that is inside the public_html folder will be recognized as mime-type Application/octet-stream and will be downloaded when accessed via web browser. If you want to enable PHP processing when using userdir this is what you need to do. First you edit following Apache configuration file in this way:

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

Now you need to comment out a line php_admin_value engine Off


 <IfModule mod_userdir.c>
 <Directory /home/*/public_html>
 php_admin_value engine Off


 <IfModule mod_userdir.c>
 <Directory /home/*/public_html>
 # php_admin_value engine Off

Save and exit, then reload apache2 configuration with following commad:

sudo /etc/init.d/apache2 reload

To testing PHP script work or not in the public_html directory, you can create some php script. In this case we are using phpinfo, in terminal type following command

echo '<?php phpinfo(); ?>' > ~/public_html/info.php

If you done, open the web browser then access http://[hostname]/~username/info.php.

Link Reference :

Tags: #Apache2 #Ubuntu Server #Userdir

How to Install LAMP in Ubuntu Server 14.04 LTS
How to Install LAMP in Ubuntu Server 14.04 LTS
This tutorial will explains basic step how
Must read×