Free SSL Certificate Setup for WordPress on Google Cloud (Bitnami)

September 15, 2017Leron AminComments Open

IMPORTANT: There is an updated version of this tutorial available here.

In this quick-start tutorial you will learn how to configure free, auto-renewing SSL certificates for WordPress websites that are hosted on Google Cloud Platform compute engine using the Bitnami version of WordPress on Google Cloud Platform.

Having SSL Security on your website will improve your Google search ranking.

If you’re using the Click-to-Deploy version of WordPress on Google Cloud Platform, you can view that SSL certificate tutorial here.

Before getting started with this tutorial, you should have already:

  1. Installed WordPress on Google Cloud
  2. Set up a Domain Name for your WordPress website
  3. Reserved a Static IP Address for your VM instance.

1. Connect to WordPress via SSH

ssl certificates wordpress on google cloud platform access menu
Go to your Google Compute homepage and click the hamburger menu in the upper left-hand corner.
ssl certificate for wordpress on google cloud platform compute engine vm instances
Go to your Compute Engine, then to VM instances to access your WordPress installation.
ssl certificate setup for wordpress on google cloud platform compute engine
Once inside your Compute Engine, click on the SSH button to connect to your WordPress installation.

2. Install CertBot Client

ssl certificate setup wordpress google cloud platform compute engine bitnami
Now that you’ve connected to your website’s Apache server, you are going to execute the command to install the Certbot client. The Certbot client is used to issue the SSL certificates that will be used later on in this tutorial.
wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto

After executing each of these commands, you can either stay in the same SSH window or exit and open a new one.

3. Generate Certificates

ssl certificate setup wordpress google cloud platform bitnami
In this step you are going to execute the command below in order to tell the Certbot client to create SSL certificates for your website. Remember to replace 1pagezen.com with your own domain name.
./certbot-auto certonly --webroot -w /opt/bitnami/apps/wordpress/htdocs/ -d 1pagezen.com -d www.1pagezen.com
ssl certificate setup wordpress google cloud platform bitnami
After entering these commands, your certificates will be generated. Take note of the directory where your certificates are installed.

Note: Instructions for testing the certificate auto-renew script were moved here.

4. Test Certificate Renewal

ssl certificate setup wordpress google cloud platform compute engine bitnami
Before setting up auto-renewal for your certificates, you are first going to execute the commands below in order to test the auto-renewal function.
./certbot-auto renew --dry-run
ssl certificate setup wordpress google cloud bitnami
If you get a success message, it means that the certificates are renewing properly.

5. Setup Auto-Renewal

Important Notice: The auto-renew configuration instructions outlined in this section are no longer valid. For updated instructions on configuring auto-renewal, click here. Before configuring auto-renewal, you should skip to step 6 and finish the tutorial first.

ssl certificate setup wordpress google cloud platform compute engine bitnami
In order to program your certificates to automatically renew themselves, you need to configure a crontab that will automatically renew the SSL certificates before they expire.
sudo crontab -e 
ssl certificate setup wordpress google cloud platform compute engine bitnami
After entering the crontab -e command, choose the text editor to use to create the crontab. Nano (1) is the easiest text editor to use.
1
ssl certificate setup wordpress google cloud click to deploy
Now that you’ve created a new crontab file, scroll to the bottom and paste the commands listed below. The command will tell Certbot to check for renewals twice per day.
0 0 * * * ./certbot-auto renew --quiet --no-self-upgrade
  
0 12 * * * ./certbot-auto renew --quiet --no-self-upgrade

After adding this code, enter ctrl+o to save changes, followed by ctrl+x to exit back to your home screen.

6. Configure the Certificates

ssl certificate setup wordpress google cloud platform compute engine bitnami
The next step is to configure your certificates. First, execute the command below to open your bitnami.conf file for editing.
sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf

ssl certificate setup wordpress google cloud platform compute engine bitnami
Next, paste the following 3-lines of code below the DocumentRoot line of the bitnami.conf file. This will tell the server to always serve your website's pages with HTTPS encryption. Remember to replace 1pagezen.com with your own domain name. (Update 03/08/2018: 'permanent' added to code to mark redirect as a 301 instead of 302).
ServerName www.1pagezen.com
  
ServerAlias 1pagezen.com
Redirect permanent / https://www.1pagezen.com/
ssl certificate setup wordpress google cloud platform compute engine bitnami
Next, use the down-arrow key to scroll down the page. Place a # sign next to each of the two placeholder certificates, and paste the path to your three SSL certificate files as shown in the command below, making sure to replace 1pagezen.com with your own domain name.
SSLCertificateFile "/etc/letsencrypt/live/1pagezen.com/cert.pem"
  
SSLCertificateKeyFile "/etc/letsencrypt/live/1pagezen.com/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/1pagezen.com/chain.pem"

After adding this code, enter ctrl+o to save changes, followed by ctrl+x to exit back to your home screen.

7. Update Domain URLs

Changing your website URLs via Settings > General is disabled in the Bitnami version, so you'll need to change your URLs by editing your wp-config.php folder.

ssl certificate setup wordpress google cloud platform compute engine bitnami
In order to open your wp-config.php file for editing,
run the command below.
sudo nano /opt/bitnami/apps/wordpress/htdocs/wp-config.php
ssl certificate setup wordpress google cloud platform compute engine bitnami
Inside of your wp-config.php file, you will need to replace your SiteURL and HomeURL definitions as shown below.

  REPLACE THIS:
  

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');


WITH THIS:

define('WP_HOME','https://www.1pagezen.com');
define('WP_SITEURL','https://www.1pagezen.com');

Remember to replace 1pagezen with either the www. or non-www. version of your domain name - whichever your prefer. For example:


  define('WP_HOME', 'https://1pagezen.com');
define('WP_SITEURL', 'https://1pagezen.com');

After adding this code, enter CTRL+o to save changes, followed by CTRL+x to exit back to your home screen.

8. Restart your Apache Server

ssl certificate setup wordpress google cloud platform compute engine bitnami
In order for your certificate changes to take effect, you need to restart you Apache server by entering the command below.
sudo /opt/bitnami/ctlscript.sh restart apache

9. Additional Resources

Now that you've completed the tutorial, you should configure your certificates to auto-renew using this tutorial. Also, if your configuration isn't working properly, check out the tutorial below to learn about common SSL errors and how to fix them.

configure ssl auto renew

ssl certificate errors on google cloud

Did it Work?

If your SSL certificates were configured properly, you will notice that your website is being loaded with a green padlock icon.

To configure certificate auto-renewal, please view the tutorial here.

If you have any questions or comments, please post them below!

Thanks,

signature

Up Next...

google cloud ftp setup filezilla
Manage WordPress Files on Google Cloud Platform

Leave a Reply

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

Made with by

© 2020 One Page Zen Systems, LLC  
Legal  |  Privacy Policy  |  Affiliate Disclosure  |  Contact  

Join our Mailing List!

Exclusive early access to the latest tutorials

Monthly update with a list of upcoming tutorials

Special access to members-only events and webinars