In this article, we want to teach you how to install Apache Web Server on Centos 7.
Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development; it quickly became the most popular HTTP client on the web.
Steps To Install Apache on centos 7
Before you start to install Apache, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.
Now follow the steps below to Set up Apache on your server.
Installing Apache Web Server on Centos 7
For installing Apache on centos 7 you can follow these steps:
1) You should update the Apache HTTPd package with the following command:
sudo yum update httpd
2) then install the Apache package by this command:
Sudo yum install httpd
3) In this step you should enable the firewall’s HTTP service with the following command:
sudo firewall-cmd --permanent --add-service=http
Note: if you see an error that firewall-cmd doesn’t exist, you should install firewalld and then run the above command.
For installing Firewalld on CentOS 7, you can use the following commands:
yum install firewalld systemctl start firewalld systemctl enable firewalld
You can find the complete guide in our article Set up a Firewall with firewalld on Centos 7.
After installing and starting the firewall service, you should add the HTTP service in section 3.
4) Enable the HTTPS service with the following command:
sudo firewall-cmd --permanent --add-service=https
5) You should reload the firewall with the following command:
sudo firewall-cmd --reload
After the firewall reloads, you are ready to start the service and check the webserver.
Start and check the Apache webserver
Apache does not automatically start on CentOS once the installation completes. You will need to start the Apache process manually by following these steps:
1) Start httpd with the following command:
sudo systemctl start httpd
You will see an active status in your output when the service is running.
2) To access your Apache page on Centos 7 you need your IP address. In two ways you can get your IP address :
• Type this command on your command line
• Or you can use curl to request your IP from icanhazip.com, which will give you your public IPv4 address as seen from another location on the internet:
curl -4 icanhazip.com
When you have your server’s IP address, enter it into your browser’s address bar:
You’ll see the default CentOS 7 Apache web page like the image below.
Now the service is installed and running, you can now use different systemctl commands to manage the service.
Managing the Apache process
1. To stop your Apache webserver on Centos 7, use the following command:
sudo systemctl stop httpd
2. To start your webserver use the following command:
sudo systemctl start httpd
3. To stop and start your webserver use this command:
sudo systemctl restart httpd
4. If you make configuration changes you can reload your web server by this command:
sudo systemctl reload httpd
5. To disable your webserver use the following command:
sudo systemctl disable httpd
6. To enable your webserver use this command:
sudo systemctl enable httpd
At this point, you learn to Install Apache on Centos 7.
Hope you enjoy it.
Also, you can secure your Apache webserver with Let’s Encrypt. To do this, you can follow our article How to Secure Apache with Let’s Encrypt on CentOS 7.