How do I create web pages in my home directory and have the web server serve them in my web browser?

You're probably looking for mod_userdir: "This module allows user-specific directories to be accessed using the http://example.com/~user/ syntax."

Don't be scared of fiddling with the config, just have backups of the config files and make sure your firewall blocks your apache to the outside world.


As Ulrich said, you can do this by enabling the userdir module.

On Debian, this can be done by using the a2enmod utility, which enables or disables Apache modules. See man a2enmod.

In this case, you just need to run

sudo a2enmod userdir

and then restart the Apache server to make the change take effect. Note that the userdir module is in base Apache, so you don't have to install anything extra. For reference the userdir config is in /etc/apache2/mods-available/userdir.conf.

All a2enmod is doing here is creating a symbolic link from the /etc/apache2/mods-enabled directory to the files /etc/apache2/mods-available/{userdir.conf/userdir.load}. You could also do this manually. I.e.

faheem@orwell:/etc/apache2/mods-enabled$ ls -la userdir.*
lrwxrwxrwx 1 root root 30 Feb  6 03:11 userdir.conf -> ../mods-available/userdir.conf
lrwxrwxrwx 1 root root 30 Feb  6 03:11 userdir.load -> ../mods-available/userdir.load

Then put whatever web stuff you want to make available under ~/public_html, and then it should be acccessible from http://servername/~username.


Personally I've used symbolic-links, depending of the project either to have link inside /var/www/ or /var/www itself being link to one of the folders in mine home directory (for example:~/projects/www). That way I can get rid of the "~" character. Sometimes it's also useful for me, when I want to show something to some other viewer (via something like: http://253.153.87.231/page.html), and one's not that familiar with the keyboard, so he just couldn't find the "~" symbol from the keyboard (-kinda like looking for the key labeled "any").

Faheem and Ulrich probably cave you the best and most commonly recommended answer already anyway (at least, when security is concerned).