Create Your Own Web Server With BIND And Apache On CentOS 5 (Simplified) - Page 2

Jumping again :) This time a bit further to line 1005 there you should see:

NameVirtualHost *:80

The NameVirtualHost directive tells Apache that we want to use name-based virtual hosting, or in simpler terms, a bunch of web sites all using the same IP address. Add a couple blank lines underneath '#NameVirtualHost *:80' and on the line right below put NameVirtualHost and your hostname or IP address followed by a :80. The ':80' means we're using name-based virtual hosting for the HTTP protocol.

So you should produce something like this:


Now we are almoust done configuring our httpd.conf file. The only thing left for us to configure is if someone visits our server using the IP rather then domain name we will set our default hostname to be visible by those users. We can insert this at the end of configuration file

    ServerAdmin [email protected]
    DocumentRoot /www
    ErrorLog logs/error_log
    CustomLog logs/access_log common
In order to keep our httpd.conf easier to manage we should add this line at the bottom of the file:
Include conf/vhosts/*.conf

Meaning that we will include all .conf entries from /etc/httpd/conf/vhosts where we will store virtual hosts for our websites as we add them. It will be easier to understand as we progress further. Ok we are almoust done, save httpd.conf and go on.

Creating web site directories

We should now create web site directory structure in order to manage our websites properly. Firstly let's create the main directory:

mkdir /www

We are now making root the owner of /www:

chown root.root /www

Before going any further we need to make one adjustment, we must add a zone for into our named.conf because we used it as a hostname in httpd.conf and we will get error if we don't do it. So we should add this to named.conf

zone "" IN {
        type master;
        file "/var/named/";

And of course below is the content of the file:

$TTL 14400
@      86400    IN      SOA [email protected] (
                2008021501      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400 )         ; minimum, seconds 86400 IN NS 86400 IN NS IN A IN A

You can add as many records as you wish. Before restarting named make a link:

ln -s/var/named/chroot/var/named/ /var/named/

service named restart

Now we go back to the directory structure. So we have added a zone for our now we need a virtual directory for it.

cd /www
mkdir html
mkdir html/cgi-bin
mkdir databases
mkdir logs

Since we have made a directory for our website, all we need is a user which will be legible to manage this domain name. We can do that with:

useradd -d /www/your-domain/ domain_user

or if you want to restrict shell access to the user use this:

useradd -d /www/your-domain/ -s /sbin/nologin domain_user

After the user has been added we can modify its password with:


This user still doesn't have his "home" :) place which he owns, now we add this:

cd /www && chown domain_user:domain_user

If you create a "databases" directory then you'll need to change the owner to the mysql user otherwise MySQL won't be able to write to the database files. All directories, subdirectories, and files dealing with databases should be owned by the mysql user and we can do that with this command:

cd && chown -R mysql:mysql databases

With this we completed the creation of the website directory structure, now the only thing left to do is to tell Apache where our website is and we are all done.

Now let's track back a bit when we were configuring httpd.conf we inserted a line there:

Include conf/vhosts/*.conf

Now you will figure out why we did that if you didn't already. Since the folder doesn't yet exist we should create it:

cd /etc/httpd/conf && mkdir vhosts

Now we go inside the vhosts directory:

cd vhosts

and we create a new file for our domain:


We should insert the following into this file:

    ServerAdmin [email protected]
    DocumentRoot /www/
    ScriptAlias /cgi-bin/ /www/
    ErrorLog /www/
    CustomLog /www/ combined

We finally reach the end point now when we told apache where ithe directory of our website is, now every request from browser for will be read from /www/; in there you should put your files ex: index.html. Now we can turn our httpd on, or restart if it was on already.

service httpd start


service httpd restart

If you are experiencing any problems with this tutorial or with the configuration of either Apache or BIND don't hesitate to contact me. I'm sure I had those and even worse problems - I'll be glad to help in my spare time.

Author : Emir Ibrahimbegovic
E: [email protected]
Thanks to: Tony Bhimani, Sébastien Wains, Nayyar Ahmad
Share this page:

0 Comment(s)

Add comment


From: c0mrade