How to install Apache Web Server on Centos 8

Pinterest LinkedIn Tumblr

In this guide, we will explore installing Apache Web server on a Centos 8 server.

The Apache HTTP Server(Apache), is one of the most popular free and open-source cross-platform web server software, released under the terms of Apache License 2.0.

The Apache is popular as part of the LAMP setup, being the A in the Acronym. The apache server functionality can be extended with the many available modules.


  • Up to date Centos 8 Server
  • Root access to the server (Or user with sudo access)
  • Firewall set up to allow traffic to port 80 and 443

Installing Apache

Ensure packages are up to date:

sudo dnf -y update

Apache is available in the default CentOS 8 software repositories as httpd. You can check info about it using this command:

sudo dnf info httpd

You should see something similar to this:

$ sudo dnf info httpd
CentOS Linux 8 - AppStream                                          20 MB/s | 8.8 MB     00:00
CentOS Linux 8 - BaseOS                                               24 MB/s | 5.6 MB     00:00
Last metadata expiration check: 0:00:01 ago on Sat 28 Aug 2021 01:06:59 PM UTC.
Available Packages
Name         : httpd
Version      : 2.4.37
Release      : 39.module_el8.4.0+778+c970deab
Architecture : x86_64
Size         : 1.4 M
Source       : httpd-2.4.37-39.module_el8.4.0+778+c970deab.src.rpm
Repository   : appstream
Summary      : Apache HTTP Server
URL          :
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

Install it with this command:

sudo dnf install -y httpd

Enabling http and https in firewalld

If you have firewalld up and running, you need to enable the http and https ports using these commands:

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

Now reload the firewall to put these new rules into effect:

sudo firewall-cmd --reload

Starting and enabling httpd service

By default, the service is not started. Confirm with the following command:

sudo systemctl status httpd


$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd.service(8)

Start the service with this command:

sudo systemctl start httpd

You will receive an active status when the service is running
Confirm that its now working fine:

$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-08-28 13:32:17 UTC; 17s ago
     Docs: man:httpd.service(8)
 Main PID: 65827 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 23800)
   Memory: 28.9M
   CGroup: /system.slice/httpd.service
           ├─65827 /usr/sbin/httpd -DFOREGROUND
           ├─65828 /usr/sbin/httpd -DFOREGROUND
           ├─65829 /usr/sbin/httpd -DFOREGROUND
           ├─65830 /usr/sbin/httpd -DFOREGROUND
           └─65831 /usr/sbin/httpd -DFOREGROUND

Aug 28 13:32:17 test-app-server systemd[1]: Starting The Apache HTTP Server...
Aug 28 13:32:17 test-app-server httpd[65827]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8fc:23ff:fe51:cc>
Aug 28 13:32:17 test-app-server systemd[1]: Started The Apache HTTP Server.
Aug 28 13:32:17 test-app-server httpd[65827]: Server configured, listening on: port 80

The above confirms that apache is working fine now.

To confirm that the service is accessible, please head to the following url to see if you can get the httpd page:


If you don’t know the server up, use the following command in your terminal:

curl -4

Once you visit that page,if everything is working fine you should see apache default page like in the screen shot below:

Apache Default Page Centos 8

Apache Default Page Centos 8

To ensure that the service is always started on boot, use this systemctl command:

sudo systemctl enable httpd

Setting Up Virtual Hosts

With Apache, it is possible to host multiple sites on the same server where the Apache is running. This can always be achieved using multiple domains each representing a site that the server is hosting.

Apache virtual hosts are similar to Nginx server blocks . Each virtual host will have configuration details for a single host. You can have as many virtual hosts as you want.

In this example, we will use the domain for the virtual host but be free to use the domain of your choice. Please note that the DNS for the domainto be used should already be configured to point to the IP address of the server.
Confirm that with:

dig -t A

Creating directory and sample content

The default page of apache is configured as a default virtual host serving content from /var/www/html. It’s a best practice to create the directory of your site in the /var/www directory since its a best practice to serve from there.

Lets create a directory for our site with the following command:

sudo mkdir /var/www/

Lets create a simple index.html page to serve from our site. You will require vim installed for this to work, if not use this command:

sudo dnf install -y vim

Edit the file:

sudo vim /var/www/ 

Add content to the file:

    <title>Hello from Citizix Site1!</title>
    <p>This is citizix site1. Welcome here.</p>

Finally, lets make sure that the current user owns the site directory:

sudo chown -R $USER:$USER /var/www/

Creating virtual host

Apache Virtual host files specifies the configuration of each sites and tell the Apache web server how to respond to various domain requests.

The Apache configurations will be stored in the directory /etc/httpd/conf.d/. Lets create a config for our site:

sudo vim /etc/httpd/conf.d/

Add the following content:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog /var/log/httpd/
    CustomLog /var/log/httpd/ combined

This will tell Apache the following:

  • ServerName and ServerAlias – name of the host to serve
  • DocumentRoot – where to find the root directly that holds the publicly accessible web documents
  • ErrorLog – where to store error logs for this site
  • CustomLog – where to store request logs for this particular site

Save and close the file when you are finished

Testing the Virtual Host

Now that the configuration is in place, we need to test that everything is working as expected.

First restart apache to reload config:

sudo systemctl restart httpd 

List the contents of the /var/log/httpd/ directory to see if Apache created the log files:
If all is well, you should see output similar to this:

# ls /var/log/httpd/
access_log  error_log

If all is well, Apache will now serve your domain name. You can test this by navigating to, where you should see something like this:

Site1 Citizix

Site1 Citizix Example

The above screenshot confirms that the virtual host is successfully configured and serving content.

If you need to host multiple other sites, repeat the steps above for the sites you want.


We managed to install and set up Apache web server in the above instructions in Centos 8 Server.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment