How to Install Apache on CentOS 8

Introduction

Apache is an open-source web server that is used to host websites and web applications. It is one of the most popular web servers in the world and is used by many large companies. Installing Apache on CentOS 8 is a straightforward process that can be completed in a few simple steps. In this guide, we will show you how to install Apache on CentOS 8. We will also provide some basic configuration steps to get your web server up and running.

How to Install Apache on CentOS 8

1. Update the system:

sudo dnf update

2. Install Apache web server:

sudo dnf install httpd

3. Start the Apache service:

sudo systemctl start httpd

4. Enable the Apache service to start on boot:

sudo systemctl enable httpd

5. Check the status of the Apache service:

sudo systemctl status httpd

6. Open the firewall port for Apache:

sudo firewall-cmd –add-service=http –permanent

7. Reload the firewall:

sudo firewall-cmd –reload

8. Test the Apache installation by opening a web browser and navigating to http://localhost. You should see the Apache test page.

Introduction

Apache is a popular Linux-based web server application. It is part of the LAMP stack (Linux, Apache, MySQL, PHP) that powers much of the internet.

This guide will show you how to install Apache on CentOS 8.

Tutorial on how to install Apache on CentOS 8

Prerequisites

  • A system running CentOS 8 Linux
  • Access to a terminal window / command line (CtrlAltF2)
  • A user account with sudo or root privileges

Installing Apache Web Server on CentOS 8

Step 1: Update Software Repository

Open a terminal window, and update the repository package lists by entering the following:

sudo yum update
Confirmation screen to verify repository package list update

Step 2: Install Apache

Now you can install Apache with the command:

sudo yum –y install httpd
apache installed on CentOS 8 successfully

Note:httpd” is the name for the Apache service in CentOS. The –y option automatically answers yes to the confirmation prompt.

Step 3: Start and Manage Apache Web Server

Apache is a service that runs in the background.

Start the Apache service by entering the following:

sudo systemctl start httpd
terminal command to start Apache service in CentOS 8

The system doesn’t return an output if the command is run properly.

To configure Apache to run on startup:

sudo systemctl enable httpd
Command to enable Apache on startup

To check the status of the Apache service:

sudo systemctl status httpd
example of an active Apache httpd service

To reload Apache (reloads configuration files to apply changes):

sudo systemctl reload httpd

To restart the entire Apache service:

sudo systemctl restart httpd

To stop Apache:

sudo systemctl stop httpd

To disable Apache at system startup:

sudo systemctl disable httpd

Step 4: Test Apache Web Server

Your Apache software’s job is to serve web pages over a network. Your new Apache installation has a default test page, but you can also create a custom test page.

Check the Default Apache Test Page

In a terminal window, find your system’s IP address with the following:

hostname -I | awk '{print $1}'
How to find your system's IP address.

If you’re familiar with the ip addr show or ifconfig commands, you can use those instead.

Open a web browser and type in the IP address displayed in the output. The system should show the Apache HTTP Server Test Page, as seen in the image below:

Image of the Apache test page.

If your system doesn’t have a graphical interface, use the curl command:

curl [your_system's_IP_address]:80

Note: The :80 at the end stands for port 80, the standard port for internet traffic. Be sure to write the appropriate IP address instead of [your_system’s_IP_address].

Optional: Create an HTML File to Test

If, for some reason, you need or have a custom HTML page you want to use as a test page, do the following:

In a terminal window, create a new HTML index file:

echo My Apache Web Server on CentOS 8 > /var/www/html/index.html

Edit the file to your liking and save it.

Now you can follow the steps in the previous section (check your IP address and browse to it in a web browser or use the curl command).

Your Apache server is working correctly if it displays the specified custom page.

Step 5: Adjust Firewall for Apache

The firewall on your system blocks traffic on different ports. Each port has a number, and different kinds of traffic use different ports. For your web server, you’ll need to allow HTTP and HTTPS traffic on ports 80 and 443 (respectively).

In a terminal, enter the following:

sudo firewall-cmd --permanent --zone=public --add-service=http
command to change firewall for Apache traffic
sudo firewall-cmd --permanent --zone=public --add-service=https

Restart firewalld:

sudo firewall-cmd --reload

Double-check to make sure your firewall is correctly configured:

sudo firewall-cmd --list-all | grep services

You should see http and https in the list of allowed services.

http and https displayed in services

Apache also offers ModSecurity, a plug-in module that works as a firewall. You can install and configure ModSecurity as an additional safety layer, which helps you monitor traffic and respond to any irregularities.

Apache Files and Directories

Apache is controlled by applying directives in configuration files:

  • /etc/httpd/conf/httpd.conf – Main Apache config file
  • /etc/httpd/ – Location for all config files
  • /etc/httpd/conf.d/ – All config files in this directory are included in the main confog file
  • /etc/httpd/conf.modules.d/ – Location for Apache module config files

Note: When making changes to configuration files, remember to always restart the Apache service to apply the new configuration.

Diligently check Apache log files to monitor your web server:

  • /var/log/httpd/ – Location of Apache log files
  • /var/log/httpd/access_log – Shows a log of systems that accessed the server
  • /var/log/httpd/error_log – Shows a list of any errors Apache encounters

Designate a directory to store the files for your website. Use the configuration files to point to the directory you choose. Some typical locations include:

  • /home/username/my_website
  • /var/www/my_website
  • /var/www/html/my_website
  • /opt/my_website

Conclusion

You should now have a working Apache web server on your CentOS system. Next, you may be interested in installing a full LAMP stack.

How to Install Apache on CentOS 8

Apache is an open-source web server that is used to host websites and web applications. It is one of the most popular web servers in the world, and it is used by many large companies and organizations. In this tutorial, we will show you how to install Apache on CentOS 8.

Prerequisites

Before you begin, you will need to have a CentOS 8 server with a non-root user with sudo privileges. You can learn how to set up a user with these privileges by following our How To Create a Sudo User on CentOS 8 tutorial.

Step 1 — Installing Apache

The Apache web server is available in the default CentOS 8 repositories. We can install it by running the following command:

sudo dnf install httpd

Once the installation is complete, start the Apache service and enable it to start on boot with the following command:

sudo systemctl start httpd
sudo systemctl enable httpd

You can check the status of the Apache service with the following command:

sudo systemctl status httpd

You should see the following output:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-08-17 11:45:17 UTC; 1min 10s ago
     Docs: man:httpd.service(8)
 Main PID: 809 (httpd)
    Tasks: 213 (limit: 4704)
   Memory: 33.3M
   CGroup: /system.slice/httpd.service
           ├─809 /usr/sbin/httpd -DFOREGROUND
           ├─810 /usr/sbin/httpd -DFOREGROUND
           ├─811 /usr/sbin/httpd -DFOREGROUND
           ├─812 /usr/sbin/httpd -DFOREGROUND
           └─813 /usr/sbin/httpd -DFOREGROUND

Aug 17 11:45:17 centos8 systemd[1]: Starting The Apache HTTP Server...
Aug 17 11:45:17 centos8 systemd[1]: Started The Apache HTTP Server.

Step 2 — Configuring the Firewall

By default, the Apache web server listens on port 80. We need to open this port in the firewall to allow external access to the web server. We can do this by running the following command:

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

You can verify that the port is open with the following command:

sudo firewall-cmd --list-all

You should see the following output:

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: dhcpv6-client http ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Step 3 — Testing the Apache Web Server

At this point, the Apache web server is installed and running. We can test it by accessing the server using a web browser. Open your web browser and type the URL http://your_server_ip. You should see the Apache test page in the following image:

Apache Test Page

If you see the test page, then the Apache web server is working correctly. You can now start hosting your websites and web applications.

Conclusion

In this tutorial, you learned how to install Apache on CentOS 8. You can now start hosting your websites and web applications on your server.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?