Page 1 of 1

VirtualHosts - which default web directory?

Posted: 2013/01/06 12:16:59
by bwd2013
Hi, I'm fairly new to this and am setting up a CentOS 6 VPS, which I want to have five or six sites hosted on, and I've been reading this tutorial here:

Halfway down it says: "Creating the Web Site Directory Structure"

"Our web site directory schema should be simple yet structured. The common approach would be to use /home as the root but we won't be doing that. Our web site parent root will be /www and from within it create a directory for each domain we'll be hosting."

Before I continue and take his advice, is this the right way to do things? I am sometimes wary of tutorials in case they are out of date, or plain incorrect, and I know that the previous server I had (which was set up by Qualiteam, who make X-Cart, so I presume they were doing things right) had all the websites stores in directories in the /home directory.

I have changed the DNS for all the sites I want on this server, so they point to the server's IP address, and they are all working correctly. (And just to note, for almost all of them, the DNS seemed to update instantly - I thought it normally takes hours? Or did I just do it at the 'right time', when the DNS were being updated?)

Also, in the tutorial it says to configure virtual hosts like this:

DocumentRoot /www
ErrorLog logs/error_log
CustomLog logs/access_log combined

Is that DocumentRoot okay? Or should it be /var/www?

My server (which my first, main site is already working with), is structured

I'm not sure how to make it use /var/www as the 'root' (sorry, that's not the right word but I don't know how else to describe it) of all the sites I will have, which will be like this, presumably:



Many thanks in advance for any help you can give, I'm slowly learning it all, but don't want to do things the wrong way and then end up having to change a load of stuff in the future.

VirtualHosts - which default web directory?

Posted: 2013/01/06 12:33:22
by TrevorH
I'd recommend keeping all the document roots under /var/www simply because it makes it easer from the point of view of leaving selinux enabled as it already knows about that location and allows apache to access it correctly. I would create a subdirectory per virtual host under /var/www - e.g. /var/www/site1 /var/www/site2 etc. You'll need to create the directories and change their ownership to the same as /var/www/html but the selinux context should be automatically assigned so probably no need to have to change that unless something doesn't work.

Re: VirtualHosts - which default web directory?

Posted: 2013/01/06 13:58:34
by bwd2013
Hi Trevor, thanks very much for your help, much appreciated.
What do I do about the main site on this server (the first one I've loaded), which is in
/var/www/html ?

I wasn't sure how the server knows to look there for the site, when I visit the IP address of the server.

I tried editing the following in httpd.conf:

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "/var/www/html"

I changed the last line to

DocumentRoot "/var/www/mydomainname"

having changed the
directory's name to

but it gives an error message in my browser,

"Not Found
The requested URL / was not found on this server."

Is there another guide, like the one I linked to, that you could recommend? I wanted something I could refer back to in future, and know that I was doing it right.

Re: VirtualHosts - which default web directory?

Posted: 2013/01/06 16:05:09
by bwd2013
Okay, I think I've worked it out, through trial and a lot of error :-D

I have to keep the main site in

otherwise Apache will just display the Apache Welcome screen, if that directory is empty.

Then I create


and use VirtualHosts to redirect incoming requests from those domain names, to the correct directories.

Re: VirtualHosts - which default web directory?

Posted: 2013/01/06 16:29:28
by bwd2013
Should I be adding the VirtualHosts information for five or six sites to the end of the httpd.conf file, or should I be using the
directory, and making new .conf files in there, one for each site?

These are the last lines in my httpd.conf file:

# include VirtualHosts config files
Include conf/vhosts/*.conf

Re: VirtualHosts - which default web directory?

Posted: 2013/01/09 10:49:45
by TrevorH
Wherever possible, I try to avoid changing the distro supplied httpd.conf and I add files to /etc/httpd/conf.d to make my changes. The default httpd.conf has an "include conf.d/*.conf" line so any *.conf file in this directory is pulled in.

Re: VirtualHosts - which default web directory?

Posted: 2017/11/06 13:52:21
by jfurnas
When doing this, how do you allow the user to access said directory? I'm used to the /home/user/public_html being served for the user.

I set my virtualhosts up to be;

/var/www/html <-- main
/var/www/ <-- site1
/var/www/ <-- site2

then I created a symlink (ln -s /var/www/ /home/user/public_html/), but the directory is read access to the apache group, so I can't access it from the user (This isn't very useful). Is there another way to set this up?

Re: VirtualHosts - which default web directory?

Posted: 2017/11/06 17:33:24
by TrevorH
The way in which you do this is likely to differ considerably on CentOS 7 and you've already posted in the relevant section of that forum. We don't like to bring back ancient threads from the dead so please continue there.