How to Install Apache On CentOS 6/7

Apache HTTP server is a free, open-source and cross-platform HTTP server. And It is the most widely used web server application in the word and providing powerful features which can be extended by a wide variety of modules.

In this article,we will explain How to Install and manage the Apache web server on CentOS 6/7 Linux System.

Prerequisites

Before starting with the tutorial, make sure you are logged in as a user with sudo privileges and make sure your CentOS server can access the Internet.

Step 1. Install Apache web server

Apache web server package is available on CentOS repository, install Apache server using the following command.

sudo yum install httpd

The Apache package and the service is called httpd on CentOS.

Once the installation is completed, start and enable Apache service:

#CentOS 7
sudo systemctl start httpd
sudo systemctl enable httpd
#CentOS 6
sudo service httpd start
sudo chkconfig httpd on

Installation of Apache server creates multiple directories and files which are very much important, some important directories are listed below.

path description
/etc/httpd Main Apache root configuration directory.
/etc/httpd/conf.d Additional Apache configuration files provided by third party software.
/etc/httpd/conf/httpd.conf Main Configuration file.
/var/lib/httpd/modules Configuration files for additional modules.( SymLink to /etc/httpd/modules)
/etc/log/httpd Contains log files ( SymLink to /etc/httpd/logs)
/var/www Main web document root directory.

Step 2. Configuring the Firewall

If your server is protected by a firewall you need to open HTTP and HTTPS ports, 80and 443. Use the following commands to open the necessary ports:

#CentOS 7
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

#CentOS 6
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables save

Step 3 .Verifying Apache Installation

First, we can check the status and the version of the Apache service, with follow command:

#CentOS 7
sudo systemctl status httpd
#CentOS 6
sudo service httpd status

To Check the Apache web server version, type the following command:

sudo httpd -v

Second,Open your web browser and navigate to http://your-centos-ip-address or http://localhost, it should show the following web page, it verifies that Apache server has been installed properly.

Step 4 .Managing Apache Service

You can manage the Apache service in the same way as any other systemd unit.

To stop the Apache service:

#CentOS 7
sudo systemctl stop httpd
#CentOS 6
sudo service httpd stop

To start it again:

#CentOS 7
sudo systemctl start httpd
#CentOS 6
sudo service httpd start

To restart the Apache service:

#CentOS 7 
sudo systemctl restart httpd
#CentOS 6
sudo service httpd restart

To reload the Apache service after you made some configuration changes:

#CentOS 7
sudo systemctl reload httpd
#CentOS 6 
sudo service httpd reload

If you want to disable the Apache service to start at boot:

#CentOS 7
sudo systemctl disable httpd
#CentOS 6
sudo chkconfig httpd off

And to re-enable it again:

#CentOS 7
sudo systemctl enable httpd
#CentOS 6
sudo chkconfig httpd on

Conclusion

You have successfully installed Apache on your CentOS 6/7 server. You’re now ready to start deploying your applications and use Apache as a web or proxy server.

If you have any question or feedback, feel free to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *