Installing an Apache web server on CentOS 8: A Step-by-step guide
Introduction
On our Linux journey, a common task we may encounter is to install a web server to deliver web pages and do some testing. In this walkthrough, I will demonstrate how to install an Apache web server on a CentOS 8 Linux server.
Scenario
As a new Linux Admin, your team wants to test a webpage on their test Linux server. They would like to see if they can access the page over the internet. Your job is to install the test web server that will serve up the webpage for your team.
What we’ll need:
- Basic knowledge of how to install a Linux server
- A Desktop/laptop
- A reliable internet connection
- access to a terminal/command line interface (CLI)
- a Linux server with CentOS 8 installed
Let’s get started!
Step 1: SSH into and update your CentOS 8 server
Let’s first securely access our CentOS 8 server and ssh into it.
What you’ll need:
- Your server username
- The server’s public IP address
- The server’s password
Open up the terminal and type in the following command (replace the brackets with your credentials and server info) and hit enter:
$ ssh [username]@[Public_IP_Address]
If this is the first time ssh-ing into this server, you’ll be prompted with a ‘fingerprint’ verification, confirming that you want to log into the server. Type ‘yes’ and hit enter to confirm. You will then be prompted to enter your password.
Once the entered your password correctly, we’ve successfully ssh-ed into the server and are ready to go.
First, let’s make sure our server is up to date. Use the ‘sudo’ command to elevate the permission level so you don’t have to enter your password every time (you might still need to enter your password for this, though).
$ sudo yum update
It may seeem like nothing is happening, but give it a minute to let the server check and run updates. Once you’ve received this prompt, we’re good to go and ready to install the Apache web server. If there are updates available, type ‘y’ and continue with the update.
Step 2: Install the Apache web server
Now let’s install the Apache web server by running this command
$ sudo yum install httpd
You’ll be shown information about the Apache package and prompted to confirm the installation. Type ‘y’ to confirm.
Step 3: Start and enable the Apache server
Once the installation is complete, we’ll need to start and enable the Apache server.
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
Our Apache server is ready to go! But first, let’s check if everything is running properly. To do this, we need to check the ‘status’ of the server.
$ sudo systemctl status httpd
Everything looks good! As we can see, the server is ‘active (running)’ and will be running on port 80 (this is important. Remember this for later).
Step 4: Intstall & Configure Firewall
Before we can access and deliver a webpage to the proper IP address, we need to configure thee firewall to deliver web traffic via HTTP/HTTPS to port 80.
- Install the firewall
$ sudo yum intstall firewalld
2. Enable the firewall
$ sudo systemctl enable firewalld
3. Check the status of the firewall
$ sudo systemctl status firewalld
Now we must configure the firewall options to allow HTTP aand HTTPS traffic on port 80
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
(You should receive a ‘success’ response with each change).
4. Restart the firewall
$ sudo firewall-cmd --reload
Step 5: Test the page
Apache comes with a default start page, which will be delivered to the server’s public IP address. If everything was done correctly, we should see this page when we type in our IP address into our web browser
If you need help finding your public IP addresss, run this command:
$ curl ifconfig.me
Congrats!
You’ve successfully installed and run an Apache web server on a CentOS 8 Linux server.