Install SSL Certificate and Change To HTTPS

Summary

In this post, I will introduce how to install the SSL certificate for WordPress.

Conclusion

I did some research and tried different methods. Now I will provide the simplest ways.

  1. Apply for an SSL certificate;
  2. Download the certificate and sent it to the server;
  3. Do the following command: sudo yum install mod_ssl;
  4. Add a file httpd-ssl.conf to /etc/httpd/conf.d/, which will be loaded by httpd.conf in /etc/httpd/conf/;
    <VirtualHost 0.0.0.0:443>
    DocumentRoot "/var/www/html"
    ServerName www.domain.com
    SSLEngine on
    SSLCertificateFile /path/to/certificate/2_www.domain.com_cert.crt
    SSLCertificateKeyFile  /path/to/certificate/3_www.domain.com.key
    SSLCertificateChainFile /path/to/certificate/1_root_bundle.crt
    </VirtualHost>
  5. Restart Apache service apachectl stop and apachectl start;

Details

Apply for an SSL certificate

I applied a free personal SSL certificate in the same site (Tencent Cloud) where I bought my domain.

mod_ssl

I came across some bugs after adding the SSL configuration file.

[root@10-255-0-79 ~]# apachectl configtest
AH00526: Syntax error on line 5 of /etc/httpd/conf.d/httpd-ssl.conf:
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration

I found that in my Apache installation, mod_ssl.so was outright missing. It turns out it is separate from the base installation and was under the package mod_ssl in the yum package manager. Simply do sudo yum install mod_ssl solve this problem.

Reference

Tencent Cloud Product Doc

Leave a Reply

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