Skip to content

Apache virtual host home directory

Apache configuration is not always easy. So, this post is dedicated to Apache the VirtualHost Directive. For now I will keep it simple and just show you how to set up a VirtualHost in your home directory since that has changed with the new version and it is not obvious what you need to do.

<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias example.com
  DocumentRoot "/var/www/example.com"
  <Directory "/var/www/example.com">
    Order allow,deny
    Allow from all
    Require all granted
    Options +FollowSymLinks +Includes +Multiviews
    AllowOverride All
  </Directory>
</VirtualHost>

To explain

Line 1: Opening tag for an XML-like configuration object. *:80 means every IP address (*) on port 80, the default for HTTP.

Line 2: ServerName is the host name you want to choose.

Line 3: ServerAlias is an alternative name.

Line 4: DocumentRoot is the path where your HTML documents live. Of course, you could have PHP and other dynamic scripts there too.

Line 5: <Directory ${PATH}> can usually use the same path as DocumentRoot, but gives more control over the directory's configuration.

Line 6 prioritises allowing access. Line 7 allows access from all hosts, which is probably what you want for a public site, although this is where hosts can be restricted.

Line 8 (Require all granted) was new to this configuration and made the VirtualHost work in a home directory.

Line 9 enables symbolic links, server-side includes, and MultiViews for cleaner URLs.

Lines 11 and 12 close the configuration blocks.