VirtualHosts - which default web directory?

Support for webhosts that use CentOS
bwd2013
Posts: 10
Joined: 2013/01/06 11:56:33
Contact:

VirtualHosts - which default web directory?

Postby bwd2013 » 2013/01/06 12:16:59

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:

http://www.xenocafe.com/tutorials/linux ... /index.php

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:


ServerAdmin sales@mydomain.com
ServerName 123.123.123.123
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
/var/www/html/index.php

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:

/var/www/site1/
/var/www/site2/
/var/www/site3/
/var/www/site4/

etc.

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.

User avatar
TrevorH
Forum Moderator
Posts: 21172
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

VirtualHosts - which default web directory?

Postby TrevorH » 2013/01/06 12:33:22

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.

bwd2013
Posts: 10
Joined: 2013/01/06 11:56:33
Contact:

Re: VirtualHosts - which default web directory?

Postby bwd2013 » 2013/01/06 13:58:34

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
/var/www/html
directory's name to
/var/www/mydomainname

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.

bwd2013
Posts: 10
Joined: 2013/01/06 11:56:33
Contact:

Re: VirtualHosts - which default web directory?

Postby bwd2013 » 2013/01/06 16:05:09

Okay, I think I've worked it out, through trial and a lot of error :-D

I have to keep the main site in
/var/www/html

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


Then I create
/var/www/site1
/var/www/site2

etc.

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

bwd2013
Posts: 10
Joined: 2013/01/06 11:56:33
Contact:

Re: VirtualHosts - which default web directory?

Postby bwd2013 » 2013/01/06 16:29:28

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
conf/vhosts
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

User avatar
TrevorH
Forum Moderator
Posts: 21172
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: VirtualHosts - which default web directory?

Postby TrevorH » 2013/01/09 10:49:45

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.

jfurnas
Posts: 2
Joined: 2017/11/06 13:27:05

Re: VirtualHosts - which default web directory?

Postby jfurnas » 2017/11/06 13:52:21

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/subdomain.example.com <-- site1
/var/www/domain.com <-- site2

then I created a symlink (ln -s /var/www/domain.com /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?

User avatar
TrevorH
Forum Moderator
Posts: 21172
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: VirtualHosts - which default web directory?

Postby TrevorH » 2017/11/06 17:33:24

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.
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke