How to Install Apache on CentOS 7

Table of Contents
Install Apache on CentOS 7
Apache is the most popular and most used HTTP web server in the world. Apache is the opensource, cross-platform, powerful, stable, reliable and free web server providing features which can be extended by the wide variety of modules. It is also used as a reverse proxy server in different scenarios. In this tutorial, you are going to learn how to install Apache on CentOS 7.
Prerequisites
Before you start to install Apache on CentOS 7. You must use the credentials of user with sudo privileges.
Install Apache
Apache is already available in default software repositories. So in this tutorial, we will install Apache by using yum
package manager.
In CentOS based system Apache service is called httpd
. To install httpd
package run below command.
sudo yum install httpd
After completion of the above command, Apache is installed on your system. Run the following command to check apache
service status.
sudo systemctl status httpd
The output should look like:
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2018-04-26 07:13:07 UTC; 11s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 3049 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─3049 /usr/sbin/httpd -DFOREGROUND ├─3050 /usr/sbin/httpd -DFOREGROUND ├─3051 /usr/sbin/httpd -DFOREGROUND ├─3052 /usr/sbin/httpd -DFOREGROUND ├─3053 /usr/sbin/httpd -DFOREGROUND └─3054 /usr/sbin/httpd -DFOREGROUND
Adjust the Firewall
Now to open HTTP and HTTPS ports for Apache run following command:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Verify Apache Installation
Open your favorite browser and open below URL to verify Apache
installation.
http://YOUR_IP_ADDRESS_OR_DOMAIN_NAME/
The output should be:

If you get above output screen which contains basic information about Apache configuration, then you have successfully verified Apache installation on CentOS.
Manage Apache Process
Following are some basic commands to manage Apache
processes.
Restart apache web server type following command:
sudo systemctl restart httpd
Stop web server type following command:
sudo systemctl stop httpd
To start web server type following command:
sudo systemctl start httpd
Reload configuration file typing following command:
sudo systemctl reload httpd
Apache service will start after boot to disable this run below command:
sudo systemctl disable httpd
To enable Apache service to start after boot run:
sudo systemctl enable httpd
Apache important default files
Following are the Apache important files and directories:
- Apache main configuration file is located at
/etc/httpd/conf/httpd.conf
- Apache main configuration files directory:
/etc/httpd/
- Ports where apache can listen are defined in
/etc/httpd/ports.conf
- Virtual Host files stored at
/etc/httpd/conf.d
directory. - Error log file located at
/var/log/httpd/error.log
- Access log file located at
/var/log/httpd/access.log
- Document root for web files
/var/www/html/
Conclusion
You have successfully learned how to install Apache on CentOS 7. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to Install DataGrip on Debian 9
-
How to Install R on Debian 9
-
How to Install Dropbox on CentOS 8 Server
-
How to Install WebStorm on Ubuntu 18.04
-
How to install PHP 7.2 on Debian 9
-
How to Use Shutdown Command in Linux
-
11 Wget Command Examples in Linux (Linux File Downloader)
-
How to Install Go on Ubuntu 18.04
-
How to Install Laravel PHP Framework With Nginx on Debian 10
-
How to Install RubyMine on Manjaro 18
-
How to Install Opera Browser on Ubuntu 18.04
-
How to Install PhpStorm on Manjaro 18