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

Want to support HowtoForge? Become a subscriber!
 
Submitted by c0mrade (Contact Author) (Forums) on Mon, 2008-06-30 17:32. :: BIND | CentOS | Apache | DNS

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

This tutorial explains how you can run your own web server on CentOS 5 with the help of Apache and the BIND name server.

 

Installing necessary packages

yum install bind bind-chroot bind-libs bind-utils caching-nameserver -y

After installing the necessary packages you are ready to start configuring named.conf. You may check and see that there is no named.conf in your /etc/ directory in Centos 5. No worries here you can see a sample named.conf file. Now create the file /etc/named.conf and copy/paste the content of the sample config file - just make sure you replace website.com with your own domain name.

 

Adding Zone entries

If you have installed bind-chroot, then you will be creating your domain zone file in /var/named/chroot/var/named/ then linking it to the /var/named/ directory, if you don't have chroot create zones inside /var/named/.

Let's assume that you have chroot so let's create a zone file:

nano /var/named/chroot/var/named/website.com.db

and c/p the following to the file you've just created:
$TTL 14400
@      86400    IN      SOA     ns1.website.com. admin@website.com. (
                2008021501      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400 )         ; minimum, seconds
website.com. 86400 IN NS ns1.website.com.
website.com. 86400 IN NS ns2.website.com.
ns1                     IN A 77.77.197.69
ns2                     IN A 77.77.197.70
website.com. IN A 77.77.197.69
localhost.website.com. IN A 127.0.0.1
website.com. IN MX 0 website.com.
mail IN CNAME website.com.
www IN CNAME website.com.
ftp IN A 77.77.197.69

I'm using my home IPs as an example. I assigned ns1.website.com to 77.77.197.69 and ns2.website.com to 77.77.197.70. Now we've successfully created our first zone and two nameservers. Let's do the following to link our zone file:

ln -s /var/named/chroot/var/named/website.com.db /var/named/website.com.db

Now if you don't know your IP, you may try this:

awk 'NR==3 {print substr($0,1,14)}' /etc/hosts

This should output your IP. Or using ifconfig "inet addr:". Time to start named:

service named start

If you get [OK] means your named is working. Now is the time to contact your domain registrar and have them update your nameservers to ns1.website.com and ns2.website.com (having replaced website.com with your domain name). Now if you can ping website.com from outside this means you've configured everything properly (otherwise feel free to contact me).

 

Installing, configuring and running Apache

Firstly,

which httpd

If you get something like "/usr/sbin/httpd" means that apache is already installed - no need to run the command below, if it says otherwise run the command below.

yum install httpd -y

You may also install mod_ssl if you wish to host websites with Secure Sockets Layer (SSL) support.

yum install mod_ssl -y

You can skip this if you don't know what is this. You may want to install PHP scripting language, you can do that with this command.

yum install php*

After all this installation, you may want to start httpd on system boot, you can do that with chkconfig:

chkconfig --level 235 httpd on

Also if you want to start named on boot run the command below:

chkconfig named on

You can check the status of named and httpd at any time by running:

service named status && service httpd status

Apache's main configuration file is called httpd.conf and is located in /etc/httpd/conf/. It is important to make one copy of the configuration file so you can start over if you mess something up. We can do that with:

cd /etc/httpd/conf && cp /etc/httpd/conf/httpd.conf httpd.conf.temp

Ok since our backup configuration is safe lets start with configuring httpd.conf. Once we opened the httpd.conf with our favorite text editor vi, nano or anything else scroll to line 133 (if you are using nano press CRTL+W then CTRL+T and type the line number and you will be transfered to line 133, if using nano you can check at all times the line number you are at by pressing CTRL+C or if you are using vi just press :133, you can also check the line number in vi by pressing CTRL+G). Let's get back to editing; in line 133 you should see:

#Listen 12.34.56.78:80

and in line 134 you should see:

Listen 80

Now if you want your server to listen to only one IP you should uncomment line 133 and replace it with:

Listen yourip:80

and delete line 134 (in my server case I'll just leave the things as they are without editing anything). Now let's jump to line 235 there you should see:

#ServerAdmin root@localhost

You should uncomment and modify this with your e-mail so if users encounter errors on your website they can reach to you as a server administrator so that you can resolve the problem or be notified of its existence. Next thing we need to do is to jump to line number 266; there you should see:

#ServerName new.host.name:80

You should uncomment this line and replace it with your desired hostname. In order for this hostname to work properly you should add a zone record for hostname (ex: host.website.com). We will do that later on when we finish configuring this file.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Mon, 2010-02-15 10:46.
Example of named.conf has disappeared and cant be downloaded.
Submitted by Jim (not registered) on Fri, 2009-03-13 11:15.

Why the needless obfuscation ?  A user can just "cat" or "head" or "more" the hosts file, instead of using awk string functions.

awk 'NR==3 {print substr($0,1,14)}' /etc/hosts

Awk has its place, but not for looking at one line in a file. This kind of thing will throw beginners.  And why use conditional constructs on the command line, like this:

cd /etc/httpd/conf && cp /etc/httpd/conf/httpd.conf httpd.conf.temp

where just typing the commands is easier ?

cd /etc/httpd/conf

cp httpd.conf httpd.conf.temp

Submitted by David (not registered) on Tue, 2009-02-24 07:22.

This does not work on CentOS 5.2 build. I rebuilt the VPS several times and tried this several times, being sure to follow the directions perfectly.

Also, the named.conf link in the beginning of this article is broken.

Submitted by Anonymous (not registered) on Fri, 2012-04-06 11:58.

the named.conf link referred in previous post from 2009 is still broken.

 Looks like abandonsite....

 

Submitted by Benny (not registered) on Tue, 2012-08-07 04:26.

Hi, I used waybackmachine to trawl the internet for the missing named.txt file.

 Hope this helps!! I am about to have a crack at setting up my first Apache Server

Here it is. Best of luck!

 

################################################################################
# Server Configuration                                                         #
################################################################################
options {
	directory "/var/named";
	recursion yes;
	query-source address * port 53;
	notify no;
};
################################################################################
# Logging Configuration                                                        #
################################################################################
logging {
   
    channel query_log {
        severity info;
        print-time yes;
	file "query.log" versions 3 size 100M;
    };
    channel activity_log {
        severity info;
        print-time yes;
        print-category yes;
        print-severity yes;
	file "activity.log" versions 3 size 100M;
    };
    category queries         { query_log; };
    category default         { activity_log; };
    category xfer-in         { activity_log; };
    category xfer-out        { activity_log; };
    category notify          { activity_log; };
    category security        { activity_log; };
    category update          { activity_log; };
    category network         { null; };
    category lame-servers    { null; };
};
################################################################################
# Zone Configuration                                                           #
################################################################################
#
# Specify the root name servers
#
zone "." IN {
	type hint;
	file "/var/named/named.ca";
};
#
# Configure ourself as the host for website.com
#
Submitted by Momed Jussub (not registered) on Wed, 2014-02-05 21:57.
Thanks, Its Working