How to install Apache web server on CentOS 8 or Stream

CentOS 8 Linux is here along with rolling -based OS Stream, let’s see how we can turn them into a web server by installing opensource Apache webserver software. 

Apache web-server is a free and open-source and power a huge majority of Linux web hosting services. It can be installed on almost any Linux whether it is CentOS 8, 7 or 6; RHEL, Ubuntu, Debian etc. It is created by the Apache foundation and supports both HTTPS and HTTP protocols. On CentOS or RHEL system or their forks, it’s recognized as httpd service.

Steps to install Apache on CentOS 8 Linux

The steps here are performed on the CentOS 8, however, they are applicable and the same for Redhat 8 and CentOS stream Linux.


Open Command Terminal and login as root

To install Apache (httpd) on CentOS 8 we need root access without that this server system will not let us install anything. Moreover, if you are using the Graphical user interface, then you can access the Command terminal from the Activities menu given on the top right side taskbar.


Update system

Run the following command to update any installed packages to their latest and stable version.

dnf update

or

yum update

Note: The latest CentOS is based on RHEL 8 and now supports dnf command, however, yum still can be used as usual. However, here we are showing both.


Command to Install Apache (httpd) on CentOS 8 or Stream

So, here is the single-line command to download and install Apache web server packages. Which is given below with both yum and dnf.

yum install httpd

or

dnf install httpd

The output of the above command:

  Package                   Arch          Version                                       Repository        Size
==============================================================================================================
Installing:
 httpd     x86_64    2.4.37-11.module_el8.0.0+172+85fc1f40      AppStream             1.7 M
Installing dependencies:
 apr             x86_64        1.6.3-9.el8                                   AppStream        125 k
 apr-util     x86_64        1.6.1-6.el8                                   AppStream        105 k
 centos-logos-httpd        noarch        80.5-2.el8                                    AppStream         24 k
 httpd-filesystem          noarch        2.4.37-11.module_el8.0.0+172+85fc1f40        AppStream          34 k
 httpd-tools               x86_64        2.4.37-11.module_el8.0.0+172+85fc1f40         AppStream        102 k
 mod_http2                 x86_64        1.11.3-2.module_el8.0.0+10+abf51267           AppStream        156 k
 mailcap                   noarch        2.1.48-3.el8                                  BaseOS            39 k
Installing weak dependencies:
 apr-util-bdb              x86_64        1.6.1-6.el8                                   AppStream         25 k
 apr-util-openssl          x86_64        1.6.1-6.el8                                   AppStream         27 k

Transaction Summary
==============================================================================================================
Install  10 Packages

Total download size: 2.3 M
Installed size: 6.1 M
Is this ok [y/N]: 

When it asks for your permission to install Apache, enter Y and let it download and install this open-source web server.

command-to-install-apache-on-Centos-8
Apache installation command
Centos-Stream-Apache-installation-is-successful
httpd installation successful

Enable Apache webserver

After the successful installation, we will enable the Apache webserver service so that it can be automatically started even after booting the system The command for that is.

systemctl enable httpd

Start httpd service n CentOS 8

Now we will start the service of Apache so that we can access and install our website on it.

systemctl start httpd

The output of the above commands:

[root@localhost ~]# systemctl enable httpd
 Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
 [root@localhost ~]# systemctl start  httpd
 [root@localhost ~]#

Open HTTP firewall port 80

If you are accessing the webserver on the same local machine where you have installed it then there will be no problem. However, the moment you want to access it using some other computer remotely or even using one which is on the same network of the webserver, the CentOS 8 firewall will not let you do that. Thus, we have to open the Port number 80 in the firewall so that users can connect to our Apache webserver.
To do this use the below command.

Command to expose the http port 80 to the public.

firewall-cmd --zone=public --permanent --add-service=http

Now, reload the firewall service to make the changes into effect.

firewall-cmd --reload

In the same, way you can also open https 443 port for your Apache web server on CentOS 8.


Access webserver to test

Now, finally, its time to see whether our installed httpd server is working or not. For that simply open your browser and type web server installed CentOS 8 IP address. For example, Our system Ip is 192.168.43.85, thus the URL will be like this http://192.168.43.85:80

If you are on the same local system then you can also use localhost as well: http://localhost:80 or http://127.0.01:80.

The result will be like this:

Access-CentOS-8-webserver-to-test
Demo Apache index.html page

Install your web page or site on the webserver

To access the web directory where you can put your web files on the server follow the below command.

cd /var/www/html/

Add your files to HTML directory and after that, you can access them locally or remotely on your web server.

Other Related Articles:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.