SSH access to CentOS/RHEL 8 system Sudo privileges to user to install packages

Step 1 – Install Apache on CentOS 8

First of all, Login to your CentOS 8 or RHEL 8 system via SSH. Then install Apache2 HTTP server packages using the following command. This will also install additional required packages on your system. Wait for the installation complete

Step 2 – Manage Apache Service

Apache service is managed with systemctl command line on CentOS/RHEL 8. After installation, use the following command to enable the Apache service and then start it. Here are the other commands to stop and restart Apache service via command line.

Step 3 – Test Apache Setup

You can view the installed Apache version details using the following command. Create a test html page under default document root directory (/var/www/html). Now access your Apache server using the server’s IP address or a domain pointed to the server IP.

Step 4 – Creating VirtualHost

Let’s create the first virtual host on your Apache server. For the tutorial, we are using the sample domain “”. Here we will create a virtual host for on port 80. Create a sample index file in a directory: Then create Virtualhost configuration file and edit in editor: Add the following content at the end of the configuration file. You may change the domain name as per your domain.

Save the Virtualhost configuration file and reload the Apache service using the following commands:

Step 5 – Configure SSL VirtualHost

You can skip this step if you don’t need SSL. But the security is always the primary concern for any website. To use SSL with Apache, install the mod_ssl package on your system. For the tutorial, I have followed these instructions to generate a self signed SSL certificate for our domain. You can either use /etc/httpd/conf/ssl.conf for SSL virtual host or You can use a separate Virtual host configuration file for your domain. For example: with the following content:

Here is three terms used to configure SSL virtualhost:

SSLEngine – Set this to “on” SSLCertificateFile – Set the path of your SSL certificate SSLCertificateKeyFile – This is the private key files used to generate SSL certificate

After that enable the Virtualhost and reload the Apache service using the following commands:

Step 6 – Secure Apache Server

Security is the most important part of hosting. Hackers are ready to exploit your web server. Edit Apache main configuration file Add the following values at the end of the file:

After that edit the Apache default SSL configuration file: Here are the multiple security-related settings. Add or Update the following settings. We are not going in detailed descriptions about it but these settings are very useful for the production servers.

After making changes restart the Apache service to apply the new configuration.


All done, You are running a secured Apache server on your CentOS 8 or RHEL 8 Linux system.

How to Install Apache on CentOS RHEL 8   TecAdmin - 69