Today we are going to install Apache Web Server on our CentOS 7 instance. Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient, and extensible server that provides HTTP services in sync with the current HTTP standards.
The Apache HTTP Server (“httpd”) was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 25th birthday as a project in February 2020.
Prerequisites
Before we begin our journey, make sure you have the following:
- A server operating with CentOS 7. We will be using a Spin Servers dedicated server for this guide.
- CentOS basic firewall
- A domain name pointing towards your server.
Step 1 — Install Apache
CentOS’s software repositories come with Apache by default, so, we can use the yum
package manager to install it.
From this point, we will use the non-root user if you are not already. Now let's update the package index.
$ sudo yum update httpd
Then install Apache:
$ sudo yum install httpd
Assuming you already have firewalld
installed on the webserver, you will need to open the port 80
to allow Apache to serve requests. If not, you will need to enable thefirewalld
HTTP service using:
$ sudo firewall-cmd --permanent --add-service=http
If you will be using HTTPS (which you should), open port 443
to enable HTTPS:
$ sudo firewall-cmd --permanent --add-service=https
Reload the new firewall rules:
$ sudo firewall-cmd --reload
Apache Web Server should not be active and running. But, let's check to make sure.
Step 2 — Verify Apache Operation
Now we need to start the Apache process. CentOS does not start Apache automatically.
$ sudo systemctl start httpd
Verify status:
$ sudo systemctl status httpd
This should output active (running)
.
By doing this we know that Apache is running, but, the best way is to check the Apache landing page. Which, we can access via the server's IP address.
Paste your server’s IP address into any web browser using:
http://server-ip
And you should see the Apache landing page.
Step 3 — Run Apache at startup
These are some basic commands to operate the Apache webserver.
I assume you will want Apache to run even after a reboot. To do that use the command:
$ sudo systemctl enable httpd
If you don’t want Apache to run during boot use the command:
$ sudo systemctl disable httpd
To stop the webserver:
$ sudo systemctl stop httpd
To start the webserver:
$ sudo systemctl start httpd
To stop then start the webserver:
$ sudo systemctl restart httpd
To restart the webserver:
$ sudo systemctl reload httpd
You now have Apache web server installed on your CentOS 7 server.