Introduction
This article will show how to install Apache Webserver in CentOS 8. The server with a CentOS 8 operating system ins running in a VirtualBox application. In order to install the Apache Webserver, there are several steps to achieve it. The first step is the main installation process. After installing Apache Webserver succesfully, there are another important part consisting of several steps. Those steps are the configuration steps. The configurations steps include in adding rule to the firewall service. The other step is starting and enabling the service. Furthermore, it will add a forwarding port in a NAT interface type since it runs in a VirtualBox application.
Apache Webserver Installation Process
The first part is the installation part of the Apache Webserver. The following steps are the steps for installing Apache Webserver :
1. If the installation command execution is using a normal user, make sure that the normal user can execute all the commands. Read the article with the title of ‘How to Add User as Super User in CentOS 8 running in a VirtualBox Application’ in this link.
2. After that, just execute the installation command as exist in the following command :
[admin@10 ~]$ sudo dnf install httpd -y [sudo] password for admin: Last metadata expiration check: 0:34:11 ago on Sun 20 Dec 2020 10:30:31 PM EST. Dependencies resolved. ======================================================================================================================== Package Architecture Version Repository Size ========================================================================================================================Installing: httpd x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc AppStream 1.7 M Installing dependencies: apr x86_64 1.6.3-11.el8 AppStream 125 k apr-util x86_64 1.6.1-6.el8 AppStream 105 k centos-logos-httpd noarch 80.5-2.el8 BaseOS 24 k httpd-filesystem noarch 2.4.37-30.module_el8.3.0+561+97fdbbcc AppStream 37 k httpd-tools x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc AppStream 104 k mod_http2 x86_64 1.15.7-2.module_el8.3.0+477+498bb568 AppStream 154 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 Enabling module streams: httpd 2.4 Transaction Summary ========================================================================================================================Install 9 Packages Total download size: 2.3 M Installed size: 6.0 M Downloading Packages: (1/9): apr-util-bdb-1.6.1-6.el8.x86_64.rpm 361 kB/s | 25 kB 00:00 (2/9): apr-util-1.6.1-6.el8.x86_64.rpm 597 kB/s | 105 kB 00:00 (3/9): apr-1.6.3-11.el8.x86_64.rpm 610 kB/s | 125 kB 00:00 (4/9): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 214 kB/s | 27 kB 00:00 (5/9): httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch.rpm 742 kB/s | 37 kB 00:00 (6/9): httpd-tools-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64.rpm 344 kB/s | 104 kB 00:00 (7/9): mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64.rpm 393 kB/s | 154 kB 00:00 (8/9): centos-logos-httpd-80.5-2.el8.noarch.rpm 73 kB/s | 24 kB 00:00 (9/9): httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64.rpm 980 kB/s | 1.7 MB 00:01 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 339 kB/s | 2.3 MB 00:06 warning: /var/cache/dnf/AppStream-a520ed22b0a8a736/packages/apr-1.6.3-11.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY CentOS-8 - AppStream 65 kB/s | 1.6 kB 00:00 Importing GPG key 0x8483C65D: Userid : "CentOS (CentOS Official Signing Key) <[email protected]>" Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.6.3-11.el8.x86_64 1/9 Running scriptlet: apr-1.6.3-11.el8.x86_64 1/9 Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/9 Installing : apr-util-openssl-1.6.1-6.el8.x86_64 3/9 Installing : apr-util-1.6.1-6.el8.x86_64 4/9 Running scriptlet: apr-util-1.6.1-6.el8.x86_64 4/9 Installing : httpd-tools-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 5/9 Installing : centos-logos-httpd-80.5-2.el8.noarch 6/9 Running scriptlet: httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch 7/9 Installing : httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch 7/9 Installing : mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64 8/9 Installing : httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 9/9 Running scriptlet: httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 9/9 Verifying : apr-1.6.3-11.el8.x86_64 1/9 Verifying : apr-util-1.6.1-6.el8.x86_64 2/9 Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/9 Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/9 Verifying : httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 5/9 Verifying : httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch 6/9 Verifying : httpd-tools-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 7/9 Verifying : mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64 8/9 Verifying : centos-logos-httpd-80.5-2.el8.noarch 9/9 Installed: apr-1.6.3-11.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 centos-logos-httpd-80.5-2.el8.noarch httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 httpd-filesystem-2.4.37-30.module_el8.3.0+561+97fdbbcc.noarch httpd-tools-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64 Complete! [admin@10 ~]$
The above command pattern for Apache Webserver installation exist as follows :
sudo dnf install httpd -y
sudo : it is a command to execute a command as another user.
dnf install httpd -y : it is a command to execute a tool with the name of dnf. This tool is the next upcoming major version of yum which is a package manager for RPM-based Linux distributions. There is an additional argument ‘install’ which instruct ‘dnf’ tool to perform installation. The package name for further installation is defined as an argument. That argument is ‘httpd’. There is also an additional argument -y that it will be passed later on to confirm ‘Yes’ to proceed on the installation.
3. Don’t forget to check the program whether it has been installed or not. Just execute the following command :
dnf list installed | grep httpd
The following image displaying on how to check it using normal user. There is another additional command for executing the above command as a normal user. The following is that command :
sudo dnf list installed | grep httpd
As in the above image display, the execution of the command is done through access via SSH. This is because the server is running on a VirtualBox application. Through the port forwarding via NAT network type, the SSH remote access is going through via port 9922. Just read the article with the title of ‘How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH’ in this link.
But normally, as root with a normal SSH remote access, just execute the command :
dnf list installed | grep httpd
Apache Webserver Execution and Activation Process
After successfully installing the Apache Webserver, the following steps are to execute or to start the service or the process. The following is the steps to achieve it :
1. Continue on the previous part after successfully installing Apache Webserver. Execute the command to start the Apache Webserver’s service. Before executing the command, check the Apache Webserver’s service is available or not after the installation. Using the following command, check whether the Apache Webserver’s service is already exist :
systemctl list-unit-files | grep httpd
The execution of the above command exist as the following image :
According to the output above, there is a service with the name of ‘httpd’. So, start the service and enable it.
2. In order to start the Apache Webserver’ service and also enable it, execute the following command :
systemctl start httpd
3. After successfully starting the Apache Webservice, don’t forget to enable it with the following command :
systemctl enable httpd
The main purpose for enabling the service is just for practical purpose. By enabling it, there will be no worry to even start the service manually after rebooting the virtual server. So, the service will automatically start on the boot process of the virtual server.
Apache Webserver Access from Host Machine
After successfully installing, starting and enabling the Apache Webserver’s service, the last one is trying to access it. The access is from the host machine or the server running the VirtualBox application. It will access the Apache Webserver’s service running in a guest machine in the VirtualBox application. The following are the steps to achieve it :
1. Add the port to the firewall rule in order to allow incoming connection from any sources including the host machine. The series of the command is in the following image :
There are three commands available in the image above. Those commands are in the following sequence :
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-port
In order to read the detail of the above command sequence, just read the article with the title of ‘How to Add Rule in the Firewall to Allow Incoming HTTP Connection in CentOS 8’ in this link.
2. Add the port forwarding for the NAT interface of the virtual server as follows :
The above configuration exist in the Virtual Server’s Settings. Precisely, it exist in the Network part. Furthermore, it exist in the Advanced settings of the interface as follows :
Read the article with the title of ‘How to Add HTTP Port Forwarding Rule to access Apache Webserver of Guest Machine running in VirtualBox Manager from Host Machine’ in this link. It is about port forwarding configuration to access HTTP web service from an Apache Webserver running in the guest machine.
3. Finally, after successfully adding the port forwarding, access the web page via web browser as follow :
Well, why accessing the URL 127.0.0.1:9980 in order to ask a HTTP service from an Apache Webserver running in the guest machine ?. It is because the definition from the port forwarding said so. If there is an access in the host machine represented by 127.0.0.1 to port 9980, it will automatically directed to port 80 in 10.0.2.15. Port 80 is where the Apache Webserver is running. Port 9980 is just an example in this context. Moreover, 10.0.2.15 is the IP Address of the guest machine. So, it is that it will display the default page of an Apache Webserver.