Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Linux and Unix Linux and Unix
Search Search
Search for:
Tech Support Guy > > >

Solved: Ubuntu: wanting to change Apache2 root folder


(!)

JPLamb's Avatar
JPLamb JPLamb is offline
Computer Specs
Member with 574 posts.
THREAD STARTER
 
Join Date: Jan 2005
Location: York, UK
Experience: A bit of this & that
21-Jul-2012, 11:16 AM #1
Solved: Ubuntu: wanting to change Apache2 root folder
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
janikPilot's Avatar
janikPilot   (Michael) janikPilot is offline
Computer Specs
Member with 141 posts.
 
Join Date: Nov 2010
Location: South FL
Experience: Advanced
22-Jul-2012, 03:00 PM #2
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:

Quote:
Virtual Hosts

Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available. By default, there is one site available called default this is what you will see when you browse to http://localhost or http://127.0.0.1. You can have many different site configurations available, and activate only those that you need...
Continue reading on the link and you'll see the steps
mutex's Avatar
mutex mutex is offline
Computer Specs
Member with 1 posts.
 
Join Date: Jul 2012
Experience: Advanced
25-Jul-2012, 10:28 AM #3
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
janikPilot's Avatar
janikPilot   (Michael) janikPilot is offline
Computer Specs
Member with 141 posts.
 
Join Date: Nov 2010
Location: South FL
Experience: Advanced
25-Jul-2012, 06:51 PM #4
Quote:
Originally Posted by mutex View Post
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
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.
JPLamb's Avatar
JPLamb JPLamb is offline
Computer Specs
Member with 574 posts.
THREAD STARTER
 
Join Date: Jan 2005
Location: York, UK
Experience: A bit of this & that
29-Jul-2012, 07:03 AM #5
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑