Install Apache Web Server on CentOS 8 - Step by Step process to do it ?

The Apache HTTP server provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.

Apache is installed on most commonly Linux based distributions.

You can install Apache as part of the LAMP stack (Linux, Apache, MySQL, and PHP) that provides a robust and powerful platform for the development and deployment of web-based applications.

The HTTP Apache web server is an open-source and free web server that transfers the web content over the internet.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on their CentOS system.

In this context, we shall look into how you can install the Apache web server on the CentOS 8 system via the terminal.


How to install Apache on CentOS 8 ?

To begin, ensure that you log into the Server as the root user with sudo privileges.

Then once logged in, follow the steps given below to install Apache.


1. update packages repository

i. Open the terminal from the sidebar of the 'Activities' section and type the 'su' command to login as a root user. Enter the administrative root password.

ii. Type the below-given command in order to update the software repository of all packages list:

$ yum update


2. Install apache

In CentOS 8, you can install Apache service with the name 'httpd'. The following command you will type on the terminal to install apache on your CentOS system:

$ yum –y install httpd

The option 'y' will automatically ignore the user confirmation prompt and select 'yes' in order to complete the installation of Apache on your system.


3. Manage Apache services

Apache service runs in the background of your system. 

i. To enable or configure the Apache services, run the below-mentioned command:

$ systemctl enable httpd

ii. Now, start apache services by typing the below-given command on the terminal and then check the running status of apache services as follows:

$ systemctl start httpd
$ systemctl status httpd


Below, you will see some commands to manage apache services that are listed below:


Reload services of apache web server by using the below-given command:

$ systemctl reload httpd

To restart services again use the following command:

$ systemctl restart httpd

You can also stop apache services on your system by running the below-mentioned command:

$ systemctl stop httpd

To disable the apache service use the command as follows:

$ systemctl disable httpd


4. Adjust firewall configurations for Apache

Different kind of traffic uses different ports on web servers. 

Using the firewall, you can allow HTTP and HTTPS traffic on ports 80 and 443 respectively.

Enter the below-mentioned commands in the terminal as a root user that will open these ports permanently on your system:

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

Reload firewall configurations:

# firewall-cmd –reload

To verify the firewall configuration run the below-mentioned command:

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

You will see that HTTP and HTTPS are allowed services in the list.


5. Test Apache web server in CentOS 8

When you test apache in the web browser the default apache new installation page will display in the browser. Find your system’s IP address by using the following command:

$ hostname -I

Now, type the IP address in the URL of your installed browser. 

On this system, we are using the default available browser Mozilla firefox.

So, enter your system's IP address and test the installation of apache. 

You will see an Apache HTTP test page in the web browser.


If you are not using a graphical interface then, run the following command:

$ curl [System-IP-address]:80


How to Create an HTML file and test Apache web server ?

If you want to use a customize Html page instead of displaying the default test page of the Apache web server then, type the following command in the terminal to create an Html index page:

# echo Installation of Apache web server on CentOS 8 > /var/www/html/index.html

Now, again type your system IP address in the URL of your browser, you will see a message in your browser:

Installation of Apache web server on CentOS 8

Now, Apache is working correctly on your CentOS system if it prints the customized HTML page in your browser.


How to uninstall httpd Apache from CentOS system ?

You can also remove the httpd apache module with all its dependencies from your system by executing the following command:

# yum remove httpd


[Need urgent assistance to install missing packages on CentOS system? We are available to help you today. ]

This article covers how to install Apache web server on CentOS 8 distribution. With Apache we server, you can host web pages over the network. Apache is available within CentOS's default software repositories, which means you can install it with the dnf package manager.


To install Apache on CentOS:

1. Execute the command below to install the Apache package:

$ sudo dnf install httpd

After confirming the installation, dnf will install Apache and all required dependencies.

2. If you also plan to configure Apache to serve content over HTTPS, you will also want to open up port 443 by enabling the https service:

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

3. Next, reload the firewall to put these new rules into effect:

$ sudo firewall-cmd --reload

After the firewall reloads, you are ready to start the service and check the web server.


To check your Apache Web Server:

1. Apache does not automatically start on CentOS once the installation completes, so you will need to start the Apache process manually:

$ sudo systemctl start httpd

2. Verify that the service is running with the following command:

$ sudo systemctl status httpd

You will receive an active status when the service is running.


To manage the Apache Process on CentOS:

Now that the service is installed and running, you can now use different systemctl commands to manage the service.

1. To stop your web server, type:

$ sudo systemctl stop httpd

2. To start the web server when it is stopped, type:

$ sudo systemctl start httpd

3. To stop and then start the service again, type:

$ sudo systemctl restart httpd

4. If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, use this command:

$ sudo systemctl reload httpd

5. By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by typing:

$ sudo systemctl disable httpd

6. To re-enable the service to start up at boot, type:

$ sudo systemctl enable httpd

Apache will now start automatically when the server boots again.

Related Posts