How to install SSL Certificate in Linux (CentoOS)

Step 1: Create Your CSR with Open SSL

  • Log in to your server via your terminal client (SSH).
  • At the prompt, type the following command:

          Note: Make sure to replace server with the name of your server.

# openssl req –new –newkey rsa:2048 –nodes –keyout server.key –out server.csr
  • Generate Files.
    • You’ve now started the process for generating the following two files:
      • Private-Key File: Used to generate the CSR and later to secure and verify connections using the certificate.
      • Certificate Signing Request (CSR) file: Used to order your SSL certificate and later to encrypt messages that only its corresponding private key can decrypt.
    • When prompted for the Common Name (domain name), type the fully qualified domain (FQDN) for the site that you are going to secure.

Note: If you’re generating an Apache CSR for a Wildcard certificate, make sure your common name starts with an asterisk (e.g., *.example.com).

  •  Now, your OpenSSL .csr file is created.
  • Save Private Key

Save the generated .key file. You need it later to install your SSL certificate.

Step 2: After CSR generation provide the CSR to SSL certificate provider. They will provide you verification method to complete verification process.

Step 3: Once you have completed the verification process, the SSL provider will provide you with the SSL certificate file.

Step 4:  Installing & Configuring Your SSL Certificate.

  • Copy the certificate files to your server.

Copy the files, along with the .key file you generated when creating the CSR, to the directory on the server where you keep your certificate and key files.

Note: Make them readable by root only to increase security.

  • Find the Apache configuration file (httpd.conf) you need to edit. The location and name of the configuration file can vary from server to server—especially if you’re using a special interface to manage your server configuration.
    • Apache’s main configuration file is typically named httpd.conf or apache2.conf. Possible locations for this file include /etc/httpd/ or /etc/apache2/.
    • Often, the SSL certificate configuration is located in a <VirtualHost> block in a different configuration file. The configuration files may be under a directory like /etc/httpd/vhosts.d//etc/httpd/sites/, or in a file called httpd-ssl.conf.

One way to locate the SSL Configuration on Linux distributions is to search using grep, as shown in the example below.

Run the following command:

# grep -i -r "SSLCertificateFile" /etc/httpd/

Note: Make sure to replace /etc/httpd/ with the base directory for your Apache installation.

  • Identify the SSL <VirtualHost> block you need to configure.

If your site needs to be accessible through both secure (https) and non-secure (http) connections, you need a virtual host for each type of connection. Make a copy of the existing non-secure virtual host and configure it for SSL as described in step 4.

If your site only needs to be accessed securely, configure the existing virtual host for SSL as described in step 4.

  • Configure the <VirtualHost> block for the SSL-enabled site

i. Below is a very simple example of a virtual host configured for SSL. The parts listed in red are the parts you must add for SSL configuration.

<VirtualHost 192.168.0.1:443> 
DocumentRoot /var/www/html2 
ServerName www.yourdomain.com 
SSLEngine on 
SSLCertificateFile /path/to/your_domain_name.crt 
SSLCertificateKeyFile /path/to/your_private.key 
SSLCertificateChainFile /path/to/DigiCertCA.crt 
</VirtualHost>

ii. Make sure to adjust the file names to match your certificate files.

  • SSLCertificateFile is your certificate file (e.g., your_domain_name.crt).
  • SSLCertificateKeyFile is the .key file generated when you created the CSR (e.g., your_private.key).
  • SSLCertificateChainFile is the intermediate certificate file (e.g., CertCA.crt)

Note: If the SSLCertificateChainFile directive does not work, try using the SSLCACertificateFile directive instead.

  • Test your Apache configuration file before restarting.

As a best practice, check your Apache configuration file for any errors before restarting Apache.

Caution: Apache won’t start again if your configuration files have syntax errors.

Run the following command to test your configuration file.

apachectl configtest
  • Restart Apache.

You can use apachectl commands to stop and start Apache with SSL support.

apachectl stop
apachectl start

Note: If Apache doesn’t restart with SSL support, try using apachectl startssl instead of apachectl start. If SSL support only loads with apachectl startssl, we recommend you adjust the apache startup configuration to include SSL support in the regular apachectl start command. Otherwise, your server may require to manually restart Apache using apachectl startssl in the event of a server reboot. This usually involves removing the <IfDefine SSL> and </IfDefine> tags that enclose your SSL configuration.

  • Congratulations! You’ve successfully installed your SSL certificate.

Was this article helpful?

Related Articles