How to install and configure apache on linux centOS 6.X

Posted on October 27th, 2013

Posted By | Comments

Hi all

Today we are going to read about the installation and configuration process of apache on linux cent OS 6.X.

 

INSTALLATION PROCESS

 

1. Set the hostname of web server

[root@web ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.mydomain.com

2. Add the webserver hostname in ‘etc/hosts’ file

[root@web ~]# 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.mydomain.com
192.168.1.250   www.mydomain.com

3. Install Apache

[root@web ~]# yum install httpd* -y

4. Configure Apache

[root@web ~]# 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 root@mydomain.com
## line no 276 - Set the website name ##
ServerName www.mydomain.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 index.html

5. Create a sample index or home page

Create the index or home page html file in the ‘/var/www/html/’ directory
[root@web ~]# vi /var/www/html/index.html 
<html>
<body bgcolor=blue>
        <h1> Welcome to My Website </h1> 
</body>
</html>

6. Allow webserver through firewall

[root@web ~]# 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
[root@web ~]# 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. Installing most common required modules

Installing PHP
[root@web ~]# yum install php -y

Installing PHP Mysql Plugin
[root@web ~]# yum install php-mysql -y

Installing Mysql
[root@web ~]# yum install mysql -y
[root@web ~]# yum install mysql-dev -y
[root@web ~]# yum install mysql-server -y

8. Start Apache web server and Mysql Server

[root@web ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@web ~]# chkconfig httpd on
[root@web ~]# service mysqld start
Starting mysqld:.....                                      [  OK  ]

edenhost.com offers VPS with pre-install templates which comes with centOS/apache/MYsql server and other tools . If you got any queries about the article please comment and do not forget to share/like this article.



About -