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.
Before you start to install Apache on CentOS 7. You must have the root user account credentials of your system.
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
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
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
- Apache main configuration files directory:
- Ports where apache can listen are defined in
- Virtual Host files stored at
- Error log file located at
- Access log file located at
- Document root for web files
You have successfully learned how to install Apache on CentOS 7. If you have any queries please don’t forget to comment out.