How to install Apache web server on CentOS 8 or Stream -H2S Media

CentOS 8 Linux is here with running OS Stream based, let’s see how we can turn them into a web server by installing the open source Apache web server software.

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

Steps to install Apache on CentOS 8 Linux

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


Open the command terminal and log in as root

To install Apache (httpd) on CentOS 8, we need root access without this server system allowing us to install anything. In addition, if you are using the graphical user interface, you can access the control terminal from the Activities menu given in the taskbar at the top right.


Update system

Run the following command to update all installed packages to their most recent and stable version.

dnf update

Where

yum update

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


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

So here is the one line command to download and install the Apache web server packages. What is given below with the two Yum and dnf.

yum install httpd

Where

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 permission to install Apache, enter Yes and let it download and install this open source web server.

Apache install command
Installation-Apache-Centos-Stream-is-successful
Successful installation of httpd

Activate the Apache web server

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

systemctl enable httpd

Start the httpd service on CentOS 8

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

systemctl start httpd

The output of the above commands:

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

Open HTTP firewall port 80

If you access the web server on the same local machine where you installed it, there will be no problem. However, the moment you want to access it using another remote computer or even using one that is on the same network as the web server, the CentOS 8 firewall will not allow you to do so. . So we have to open the Port number 80 in the firewall so that users can connect to our Apache web server.
To do this, use the command below.

Command to expose http port 80 to the public.

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

Now reload the firewall service to apply the changes.

firewall-cmd --reload

Similarly, you can also open https port 443 for your Apache web server on CentOS 8.


Access the web server to test

Now, finally, it’s time to see if our installed httpd server is working or not. To do this, simply open your browser and type in the CentOS 8 IP address of the installed web server. For example our system Ip is 192.168.43.85, so the url will be like this http://192.168.43.85:80

If you are on the same local system, you can also use localhost: http: // localhost: 80 Where http: //127.0.01: 80.

The result will be like this:

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

Install your web page or site on the web server

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

cd /var/www/html/

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

Other related articles:


Source link

Comments are closed.