1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Ubuntu: wanting to change Apache2 root folder

Discussion in 'Linux and Unix' started by JPLamb, Jul 21, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. JPLamb

    JPLamb Thread Starter

    Joined:
    Jan 27, 2005
    Messages:
    577
    Hi All,

    I am new to Ubuntu and a little confused.

    i have installed Apache2 and got it working so it currently displays the "It Works" page

    I am wanting to change the default root folder from "var/www" to "/home/lambnet/Dropbox/Personal/Webserver/Live"

    when i was using windows it was a case of just changing one line in the config file but this does not seem to be the case with ubuntu. I have looked around on google and tried a few things but everything seems to say different things.

    Is anybody able to help me with this?

    Many thanks

    James
     
  2. janikPilot

    janikPilot

    Joined:
    Nov 26, 2010
    Messages:
    141
    I have been in the exact same situation as you, and I remember my frustration. I found a very good tutorial here that explained everything to me. Essentially what you do, is you have to copy the default settings, change some things, then set your copy as the default. The page I linked to is a tutorial on setting up a LAMP (Linux/Apache/MySQL/PHP) stack on Ubuntu. The section you want is entitled "Virtual Hosts". It starts out like this:

    Continue reading on the link and you'll see the steps :D
     
  3. mutex

    mutex

    Joined:
    Jul 25, 2012
    Messages:
    1
    While changing your virtualhosts setting will work ok, vhosts are usually used when your server is called www.server.com and you want to have another DNS name like www.anothername.com point to a new folder, and/or you have multiple IP addresses.

    If you edit apache's config file you can change where its looking by changing the "DocumentRoot" directive. I use fedora here at work so i googled what ubuntu uses, and i saw different answers, so im afraid I cant help you with the exact filename since I dont know what version your using. I'd guess /etc/apache2/apache2.conf or /etc/apache2/httpd.conf

    Edit that config file....near the top you'll see a line like:
    DocumentRoot "/var/www"

    Change the folder name to whatever you want to point. Also, a few lines down from DocumentRoot you'll see lines like this:
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/var/www">

    Like the comment says, change that to whatever your DocumentRoot is. This sets various options for the folder itself.

    Restart the webserver and you should be good to go. If your having trouble, watching the error_log (location is also defined in apaches config, /var/log/apache2/error_log is what google said) is a huge help when trying to get webservers to play nice. If i do anything in apache and its not working ill immediatly startup a "tail -f /var/log/httpd/error_log" (the fedora location) and often it'll tell you exactly whats wrong, sometimes even telling you what line in the config file is wrong.

    HTH
     
  4. janikPilot

    janikPilot

    Joined:
    Nov 26, 2010
    Messages:
    141
    When Apache2 is installed on Ubuntu Systems, it tends to be missing the DocumentRoot option in apache2.conf, and httpd.conf is intentionally left blank. Also, adding a DocumentRoot line to apache2.conf will be futile. Virtual Hosts is the only way to solve this problem in Apache2 for Ubuntu systems. I know it's weird, but I spent literally weeks trying to do it the way you described, to no avail. I found that the Virtual Hosts solution works best.
     
  5. JPLamb

    JPLamb Thread Starter

    Joined:
    Jan 27, 2005
    Messages:
    577
    Hello All,

    Thank you for your help and sorry for the delayed reply.

    i managed to change the default root folder using the above support, i had a few issues with permissions. I think this was partly due to me selecting Ubuntu to encrypt my directory. after playing with the files so much i did a fresh install and didn't encrypt the directory and this seems to have done the trick.

    many thanks
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1062000