How To Install Apache 2.2 on CentOS/RHEL 5/6/7?

How To Install Apache 2.2 on CentOS 5/6/7?

Apache is one the most in use web server around the world and still today it occupies 50 % of the web. We the introduction of other web servers like Nginx or lighthttpd its use is going down but still Apache is the king. By the end of this article, you will learn how to install Apache 2.2 on your server with Remi repository

Read comparison between Apache and Nginx

You just have to follow very simple steps, with YUM manager. YUM makes it really easy by avoiding the compilation process and install them easily with installing all other dependencies and also you are notified of updates.

Scenario: My Server IP is

So let’s start and Learn To Set Up  Apache 2.2

Step 1: Enable Remi Repository

The most f the updated package is available under Remi repository. Install it in your system using following commands.

CentOS/RHEL 7:
# rpm -Uvh
CentOS/RHEL 6:
# rpm -Uvh 

CentOS/RHEL 5:
# rpm -Uvh 

Fedora 20:
# rpm -Uvh

Step 2: Install Apache

After adding Remi repository, install phpMyAdmin using yum package manager. All the dependencies will automatically be installed.

# yum --enablerepo=remi install httpd mod_ssl

Step 3: Start Your Server

As Apache don’t start automatically when you install, you need to start it manually.

#service httpd  start

The following message is displayed:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
The IP address (shown in this example as is used as the server name by default. In the following steps, set the server name for the next time the server is started.

Step 4: Apache VirtualHost Configuration

#vim /etc/httpd/conf.d/vhost.conf

After this file is open make the following changes

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/

DirectoryIndex index.php index.htm index.html

#ScriptAlias /cgi-bin/ /home/www/
#<Location /cgi-bin>
# Options +ExecCGI

ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
order allow,deny
allow from all
#allow from

Now save the file using the command  #: wq!

 Step 4: Allow iptables

If you don’t have iptables running then skip this step but sometimes it happens that Centos servers are running with iptables so we have to make some changes to allow Port 80 to get our apache server live for the public domain. else Port 80 and 443(SSL) will be blocked

#iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#iptables -I INPUT -p tcp --dport 443 -j ACCEPT
#service iptables save

Note: After saving iptables restart Apache server. if Apache page doesn’t show up reboot the server and follow from step 5.

Step 5: Restart Apache Server

# Server httpd restart

Step 6: Check Your Installation

Now open a browser and Navigate to your Server IP address (for example,

How To Set Up LAMP Environment with Apache MySql and PHP ?

If you could see the page then you have successfully installed Apache on to you server

Step 7: Set for startUP configuration

As we have installed Apache and its up so make it get start automatically after every reboot you have to run following commands and your Apache server will start automatically when the server is rebooted.

#chkconfig httpd on

Some Useful Command

  1. To check httpd configuration file syntax
#httpd -t
  1. To check Apache automatic start at runlevel
#chkconfig --list httpd

output will be …

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  1. To restart Apache server
#service httpd restart

Read How To Setup LAMP environment on your server