Home Linux DistributionsCentOS Install Apache Webserver in CentOS 6.3

Install Apache Webserver in CentOS 6.3

By sk
101 Views
In this how-to tutorial I'll show you how to install Apache and host a sample website using Apache.

Scenario

In this how-to tutorial, my test scenario setup are as follows

Webserver Details:

Operating System  :  CentOS 6.3 32bit server
Hostname          :  web.ostechnix.com
IP Address        :  192.168.1.250

Client Details:

Operating System  :  CentOS 6.3 32bit Desktop
Hostname          :  client.ostechnix.com
IP Address        :  192.168.1.251
I already have a DNS server in my setup and I had properly configured the DNS server with both server and client details.

Server side configuration

Prerequisites:

1. Set the hostname of web server

[[email protected] ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.ostechnix.com

2. Add the webserver hostname in 'etc/hosts' file

[[email protected] ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   web.ostechnix.com
192.168.1.250   ostechnix.com

3. Install Apache

Check and remove any previously installed packages
[[email protected] ~]# rpm -qa | grep httpd
or
[[email protected] ~]# yum list installed | grep httpd
Now install the 'httpd' package
[[email protected] ~]# yum install httpd* -y

4. Configure Apache

[[email protected] ~]# vi /etc/httpd/conf/httpd.conf 
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin [email protected]
## line no 276 - Set the website name ##
ServerName ostechnix.com:80
## line no 292 - Set the web pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the website ##
DirectoryIndex ostechnix.html

5. Create a sample index or home page

Create the index or home page html file in the '/var/www/html/' directory
[[email protected] ~]# vi /var/www/html/ostechnix.html 
<html>
<body bgcolor=blue>
        <h1> Welcome to OSTECHNIX Website </h1> 
</body>
</html>

6. Allow webserver through firewall

[[email protected] ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Restart iptables to save changes
[[email protected] ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

7. Start Apache web server

[[email protected] ~]# service httpd start
Starting httpd:                                            [  OK  ]
[[email protected] ~]# chkconfig httpd on

Client side Configuration

1. Add the webserver and client ip address and hostname in the '/etc/hosts' file

[[email protected] ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251   client.ostechnix.com
192.168.1.250   ostechnix.com

2. Check Apache webserver

Open the firefox in client and type https://ostechnix.com in the address bar. The index page of ostechnix website will open now.
CentOS 6.3 Desktop, 1 Nic, bridge, Internet [Running] - Oracle VM VirtualBox_005
Thats it. Have a good day!!!

You May Also Like

7 comments

Ziko May 11, 2013 - 1:05 pm

Thank You Guys!

Reply
Rob May 29, 2013 - 11:44 pm

Why is the same iptables rule added twice? Did you mean for the second one to allow udp packets?

Reply
SK May 30, 2013 - 12:56 pm

Yes thats correct.

Reply
honore June 3, 2013 - 6:06 pm

thanks bro nice

Reply
UMER AZEEM July 9, 2013 - 12:44 am

Nice Sharing fir bignners like me……Thank you.

Reply
venkat November 20, 2013 - 4:28 pm

Good

Reply
Nitai Das May 14, 2020 - 12:41 pm

Very Nice, i have follow the same and get sucess.
Thank a lot

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More