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. [email protected]. (
                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.

Share this page:

6 Comment(s)