Setting up Apache 2.4 to serve files from your home directory in Ubuntu

Install the Apache web server with the following terminal command:

sudo apt-get install apache2 

This will install and start the server, so that you can visit http://localhost with you browser to see the "It's working" page.

What you see is served from /var/www/index.html (or a similar path) on your file system. /var/www is owned by root, so in order to edit files there you have to set up file- and/or group permissions in some way. I find it easier to have Apache serve the files from a directory in my own home directory, say /home/you/www. Let's set that up now!

First, make a copy of the default site configuration with

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/site1.conf

Edit the new file (I use Mousepad on Xubuntu, you might use gedit or nano):

sudo mousepad /etc/apache2/sites-available/site1.conf

In that file, find where it says DocumentRoot /var/www and change it to DocumentRoot /home/you/www. Below that line, add the following:

<Directory /home/you/www>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

Disable the default site & enable the new one (don't enable both since they will both answer to localhost!)

sudo a2dissite 000-default && sudo a2ensite site1

Finally, restart the server with

sudo service apache2 restart

Put some text in a file e.g. /home/you/www/some.html and check out http://localhost/some.html !

What else to do

  • Enable .htaccess files: Edit your site1.conf file and change AllowOverride None to AllowOverride All
  • Have more vhosts and aliases in /etc/sites, and corresponding ServerName www.example.com config
  • Install Php and have more fun.

I write this after following the excellent, but now outdated (pre-Apache version 2.4), tutorial at http://www.maketecheasier.com/install-and-configure-apache-in-ubuntu/

Tags: