Skip to content

Adding User Directories to Virtual Hosts

On Apache 2.x, UserDir is now a module. When I say UserDir, I mean the ability of Apache to allow users on your server to have their own publicly available web space via a public_html (usually) directory. This space would be accessible with a URL similar to http://<servername>/~<username>/.

I found it useful to enable the UserDir module on a virtual host. I didn’t, however, want it available to all virtual hosts on that machine. Although unintuitive, it’s pretty easy. Here’s what you do:

  1. Instead of using a2enmod userdir, you manually symlink the userdir.load file from your mods-available directory to your mods-enabled directory. That would look like this: sudo ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/. If you were to use a2enmod userdir, that would symlink the userdir.conf file as well and we don’t want that.
  2. Now include the userdir.conf configuration file within your virtual host configuration file. For example, my virtual host file is /etc/apache2/sites-enabled/ I add Include /etc/apache2/mods-available/userdir.conf anywhere between the <VirtualHost> and </VirtualHost> elements.
  3. Update your apache2.conf (or similar) file by adding: userdir disabled on a line by itself. This will disable the UserDir module in all virtual hosts that don’t have a specific configuration.
  4. Lastly, don’t forget to reload your configuration changes withsudo /etc/init.d/apache2 reload



Published inWeb Development

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *