How to: Redirect Apache’s Default www or public_html Folder to a Directory in Your Home Folder

Purpose: The default installation of Apache (from a Ubuntu-Server installation) sets the base directory for the web documents as /var/www (on Ubuntu’s installation — this may be different if you are running Apache on another machine); this may not be where you want it, in the end, and certainly isn’t as easily accessible from a remote machine. One option is to change where it is Apache searches for its web documents folder in Apache’s configuration file; another way, which I chose, is to create a symbolic link in the default location’s place and have it point to a directory in my user’s home folder.

Benefit: I can login remotely with my user name (henry) and have direct access to the web documents root folder. This makes it easy to use FTP or SSH or AFP to move files around and I don’t have to fool with user groups or permissions.

If you want to do this, login as the user you want to host the web pages and run the following from the terminal:

  • $ mkdir ~/www
  • $ sudo mv /var/www /var/www-backup
  • $ sudo ln -s /home/henry/www /var/www

This will create a www folder in your user’s home directory, change the name of Apache’s default www directory, and create a symbolic link in its place that points to the directory you recently created.

Drop a index.html file in your new ~/www directory and you are good to go!

10 Comments (newest first)

  1. Mythili says:

    /var/www/vhosts/[domain name]/conf/vhost.conf file.

    How to find this path in remote desktop.Where we have to execute this command

  2. Vinicius Cruz says:

    Boa tarde!
    Galera sou novo no linux preciso de ajuda, queria hospedar uma pagina simples html no meu servidor ubuntu server 10.10 e não sei onde colocar a pagina index.html no servidor para que ele fique vissivel.
    Por favor preciso de ajuda.

  3. acidBurn22 says:

    really helpful, thanks a lot!

  4. […] How to: Redirect Apache’s Default www or public_html Folder to a Directory in Your Home Folder « …. Share this:TwitterFacebookLike this:LikeBe the first to like this post. Categories: […]

  5. Theo says:

    Thanks for posting this. I cannot remember anything.

  6. david says:

    edit: of course with the appropriate flags for directories and files. leaving the addons folder in the root group

  7. david says:

    I usually just sudo chown “username” /var/www/html, I use it just for development purposes though.

  8. andy says:

    This seems like such a simple solution. Ive seen people who place a symbolic link in their home folder to the /var/www/ folder, but it seems like you would just be mired in permission crap anyways. Are there any possible downsides to this?

    • Damon says:

      Well, the files would have the permissions of the user’s home folder by default — but that could be changed by setting the sticky bit on the ~/www folder. I prefer to keep the files under the user folder, by default, because it is easier to backup and handle … plus, when logging in via ssh user’s can be limited to their home folder.

  9. David Nickel says:

    hi;
    Thank you; been trying to find your page this is so much better.
    been kicking my but since reinstall to find this info it helps so much.
    that’s my old site i have to tweak the new one .