How to Install Apache on CentOS 8 Linux

When we are thinking about web server the first name is coming Apache HTTP server, it is most popular in the world for hosting any type of web applications or websites.
 
The most important thing about Apache web server is, it is free and open-source web server and providing a powerful feature for your web application, including support of cross-platform.
 
In this tutorial, we will explain the process of installing the Apache HTTP webserver on CentOS 8 Operating System.

Prerequisites

To install Apache HTTP web server on your CentOS 8 Linux system, you should have user access to login on system and need sudo privileges to execute administrative commands to install applications.

Install Apache

The apache HTTP web server packages are inbuilt in CentOS repository packages which we can easily install using “yum” command. The only thing is to know the Apache HTTP server’s service is known as “httpd” in CentOS Operating System.

To install HTTP package, first, need to update CentOS package index and install httpd using the following command:

$ sudo yum update
$ sudo yum install httpd

Now, the apache httpd web server is installed. You can enable and start httpd service using following command:

$ sudo systemctl enable httpd
$ sudo systemctl start httpd

Configure the Firewall for Apache httpd server on CentOS 8

Nowadays, every system we protecting with Firewall to secure system and services. If Firewall also protests your CentOS system, you need to open HTTP (80) and HTTPS (443) port to access the webserver.

You can open the Apache ports using the following command:

$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload

Verify Apache Installation

To verify apache httpd web server installed  and everything working as per the instructions, you can check the status of httpd service status and version:

$ sudo systemctl status httpd
Output-
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-06-26 07:13:07 UTC; 11s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 3059 (httpd)
...
$ sudo httpd -v
Output-
Server version: Apache/2.4.6 (CentOS)
Server built:   Oct 19 2017 20:39:16

Manage Apache Service:

We can manage apache service in the similar of another systemd services.

To stop httpd service use following command:

$ sudo systemctl stop httpd

To start again httpd service, run following command:

$ sudo systemctl start httpd

To restart apache httpd service, use the following command:

$ sudo systemctl restart httpd

To reload apache httpd web service after any changes, run following command:

$ sudo systemctl reload httpd

To disable apache httpd service to start on boot, use following command:

$ sudo systemctl disable httpd

To enable httpd service again, use below command:

$ sudo systemctl enable httpd

Apache Configuration File’s Structure

The Apache2 configuration file’s default location is “/etc/httpd/” directory.

The main Apache2 web server configuration file is “/etc/httpd/conf/httpd.conf”.

The virtual host files configured on Apache webserver stored in the “/etc/httpd/conf.d/” directory. The configuration file ending with “.conf”.

The apache web server’s module configuration files stored in the “/etc/httpd/conf.modules.d/” directory. 

Generally  we can configure all virtual host in a single file, but I suggest to create seperate vhost files.

To troubleshoot or debug the issue with the apache web server, use the log file for apache server and virtual host. The log file for apache located at “/var/log/httpd/access.log” and “/var/log/httpd/error.log”. To make it easy to troubleshoot an issue with different virtual host need to create different access and error log for each virtual host.

There is no location boundary to create document root directory, you can create at any location but as per suggestion, the most common location for webroot directory is:
  • /var/www/<site_Name>
  • /var/www/html/<Site_Name>
  • /opt/<site_Name>
  • /home/<user_name>/<Site_Name>

Conclusion

You have learned to install Apache httpd web server on your CentOS 8 server or system. Now your system is ready to deploy a web application using Apache virtual host or use Apache as a web proxy server for your application.

Do you have any doubt, questions or feedback? Feel free to leave a comment.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Articles