Sweshi's Tutorials

Installing and configuring HTTPS in the Apache Web Server (HTTPD) in Centos 9 Linux and below

Generating the SSL Certificate and private key

NB: This tutorial assumes you have already installed the Apache web server (HTTPD). If not, follow the step In this section

HTTPS is an extension of the Hypertext Transfer Protocol (HTTP) used for secure communication over a computer network, typically the internet. It adds a layer of security by using encryption protocols such as Transport Layer Security (TLS) or its predecessor, Secure Sockets Layer (SSL). This encryption ensures that the data exchanged between the user's web browser and the website's server is encrypted and secure from potential eavesdroppers.

How to enable https in Linux: In this step I install the mod_ssl package

Install mod_ssl which is the tool that we will use to create the private and public keys needed or the SSL certificates.

How to enable https in Linux: In this step I create the ssl directory to store the certificates

Create the directory “ssl” and inside it create another directoy “html”. The path should be “/var/www/ssl/html”. You can create the directory anywhere on you system but make sure it is safe because it will store the private key and SSL certificate that will be generated.

How to enable https in Linux: In this step I navigate to the ssl directory

Navigate to the newly created directory using “cd /var/www/ssl/html” or your own equivalent.

How to enable https in Linux: In this step I generate the key.crt

Navigate to the /var/www/ssl/html directory. For the purpose of this tutorial, am placing the SSL certificate in the “DocumentRoot” i.e, /var/www/ssl/html. For your own deployment, use another directory that is not exposed to the web browsers. We want to create a certificate and private key in the directory.

The command, generates a new certificate signing request (CSR) using OpenSSL. Let's break down the command:openssl req -new > key.crt

  • openssl: This is the command-line tool for using the OpenSSL library, which provides cryptographic functionality.
  • req: This specifies that the OpenSSL tool should be used for certificate requests and related tasks.
  • new: This option indicates that a new CSR should be generated.
  • key.crt: This part of the command uses shell redirection (>) to save the output (the generated CSR) to a file named key.crt. The key.crt is the file where the CSR will be stored.
How to enable https in Linux: In this step I enter the required information

You will then be asked to enter some information that will be used in the certificate request. Enter a pass phrase, 2 letter country code, the state or province, city, organisation name, department name, hostname, email address and two extra attributes in the forms of a challenge password and an optional company name.

How to enable https in Linux: In this step I check if the key.crt and main.cert.key are generated successfully

When you list the content of the directory with “ls”, you will see that the private key and the certificate files will be generated.

How to enable https in Linux: In this step I create the main.cert.key are generated successfully

We then create the "main.cert.key" which is the unsigned certificate.

If they are generated successfully, we can then proceed to self-sign them.