
Apache web server is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that powers a large percentage of the Internet’s websites. Apache HTTP server providing powerful features which can be extended by a wide variety of modules. This guide will help you to install Apache web server on your CentOS 7 machine.
Install Apache on CentOS 7
Apache is available in the default CentOS repositories and the installation is pretty straight forward.
Prerequisites
Before starting with tutorial, You need CentOS 7 server with logged in as a sudo enabled user.
Installing Apache
We will use CentOS’s package manager yum
to install Apache. Using package manager we can install Apache easily from a repository maintained by CentOS.
On CentOS, Apache package is known as httpd
. Execute below command to install Apache package :
sudo yum install httpd
Once it installs, you can start and enable Apache on your server:
sudo systemctl start httpd
Next, run below command to enable Apache auto start on boot:
sudo systemctl enable httpd
Adjust Firewall
If your firewall enabled then you have to open http and https ports. Use below commands to open 80
and 443
ports :
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Testing Apache Installation
Finally you installed Apache and adjusted firewall so you can check status and version of Apache service by type :
sudo systemctl status httpd
Output
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-03-29 15:25:07 UTC; 11s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 5793 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─5793 /usr/sbin/httpd -DFOREGROUND
├─5802 /usr/sbin/httpd -DFOREGROUND
├─5803 /usr/sbin/httpd -DFOREGROUND
├─5804 /usr/sbin/httpd -DFOREGROUND
├─5805 /usr/sbin/httpd -DFOREGROUND
└─5806 /usr/sbin/httpd -DFOREGROUND
To check version of Apache service, type:
sudo httpd -v
It will show you output as following:
Output
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 5 2018 01:47:09
Afterwards, you can do final testing to know everything is working proper, open browser and browse with your server public ip address. It should show a CentOS apache default page as below:
http://YOUR_SERVER_IP

Managing Apache Service
You can manage Apache services by following commands:
To stop Apache service you can run :
sudo systemctl stop httpd
To again start it type:
sudo systemctl start httpd
Restart (stop and start) Apache service by typing:
sudo systemctl restart httpd
You need to reload Apache if changes made in configuration. You can do it by:
sudo systemctl reload httpd
If you want to disable the Apache service to start at boot:
sudo systemctl disable httpd
You can re-enable by:
sudo systemctl enable httpd
Conclusion
You have successfully installed Apache on your CentOS 7 system. You can now ready to start deploying your applications and use Apache as a web server.
Leave a Reply