How to Setup & Install WordPress on Google Cloud with a Free SSL in 2019

Today we’re going to take a look at how to Setup and Install WordPress on Google Cloud - Google Click to Deploy, configure OpenSource SSL, and enable essential services through Debian CLI  to keep WordPress Instance streamlined.

Setup WordPress On Google Cloud and Configure LetsEncrypt OpenSSL

Google Cloud Platform, offered by Google, is a suite of cloud computing services that run on the same infrastructure that Google uses for its end-user products, such as Google Search, Google Drive, Android,  YouTube. read more

Let's get started 


1. Setup an Instance

Get $300 To Try Google Cloud‎

Use products & Services offered by Google for free up to the specified usage limits during and past the free trial. These usage limits are subject to change and only available for eligible customers. view details

Create New Project In Google Cloud Platform

Once you’ve signed up for Trial or purchased Google Cloud, you’ll need to log into your Google account and access the Google Cloud Console. From the Project drop-down, click Create project:

Setup WordPress On Google Cloud. Create Google Cloud Project
Create Google Cloud Project

Deploy WordPress & Configure Instance.

After creating a project, Let's Click on Go to Cloud Launcher and select WordPress Google Click to Deploy on next page.

Setup WordPress On Google Cloud . Google Click to Deploy
WordPress Google Click To Deploy

 Click - Launch on Compute Engine

Setup WordPress On Google Cloud. Launch Compute Engine
Configure New WordPress Deployment in Compute Engine
  1. Enter Deployment Name - Deployment name can only contain lowercase characters, numbers or dashes. It must start with a lowercase letter and cannot end with a dash.
  2. Select Zone  - The zone determines what computing resources are available and where your data is stored and used Learn more
  3. Configure Machine Type - Machine types determine the specifications of your machines, such as the amount of memory, virtual cores, and persistent disk limits an instance will have. Learn more about machine types
  4. Enter Administrator Email - This email will be used if you need to reset your password.
  5. Select Install phpMyAdmin
  6. Boot Disk Type - Storage space is much less expensive for a standard persistent disk. An SSD persistent disk is better for random IOPS or streaming throughput with low latency. Learn more
  7. Firewall - By default, all incoming traffic from outside a network is blocked. Select the type of network traffic you want to allow. Learn more  Check both Allow HTTPS & HTTPS Traffic.
  8. Finally, Click on Deploy and Wait for Google to generate IP Address & Credentials for your WordPress Instance.
Setup WordPress On Google Cloud Deployment Manager
Deployment Manager


Step 2. Configure Domain

Update Domain's IP Address for forwarding

Furthermore, Login to your Domain Control Panel, Navigate to DNS Zone and update the IP address for forwarding in 3 simple steps.

    1. Host Name - Enter the host name the A record links to. Type @ to point the record directly to your domain name, including the www.
    1. Points to IP Address - Enter 35.188.53.143 (Example)
  1. TTL - Select how long the server should cache the information.

Note: It should take a few minutes for DNS to propagate. However, you can expect a propagation time up to 24 hours. This is because it takes time for the DNS to take effect across the internet. Make use of DNSChecker to check DNS data collected from all location for confirming that your domain is completely propagated or not worldwide.

Configure Domain in WordPress Dashboard

Once you know that the Domain is propagated. You need to update domain name in WordPress Dashboard. Simply, Go to Settings, Click on General & Replace IP Address with Domain Name.

Configure Domain In WordPress Dashboard
Click Save Changes to Setup Domain Name for your WordPress

After Saving Changes, your domain name will be updated and you will be redirected to new WordPress Login page.

Enter Same Credentials for WordPress Login
Enter Same old Credentials to Login

Step 3. Install SSL

 Configure SSL to Redirect Traffic from HTTP to HTTPS

HTTPS protects the integrity of your website. HTTPS helps prevent intruders from tampering with the communications between your websites and your users' browsers. Intruders include intentionally malicious attackers, and legitimate but intrusive companies, such as ISPs or hotels that inject ads into pages. In the next few steps, I am going to show you how to set up and configure LetsEncrypt, Certbot OpenSSL certificate.

Navigate to Deployment Manager and click on SSH to launch terminal. Also, we'll need to edit some files so here's the list of VIM Editor Commands

Setup WordPress On Google Cloud - Launch Terminal
Launch Terminal by Clicking on SSH

Run following commands in Terminal for generating SSL certificates and redirecting site from HTTP to HTTPS.

 Install Git

sudo apt-get install git
Setup WordPress On Google Cloud . Install Git Via Command Line
Install Git Via Command Line

 Clone Certbot from Git and configure SSL 

You can directly install a Certbot package on your Instance from Github by running the following command.

sudo clone git https://github.com/certbot/certbot.git
Setup WordPress On Google Cloud. Clone Certbot from Github
Clone Certbot from Github

Go to Certbot directory

cd certbot

Run Certbot-Auto Package

./certbot-auto
Run Certbot Auto-Package
Run Certbot Auto-package

Important Steps of Configuration: 

  • Agree with terms and conditions
  • Enter your Email address to receive expiry notifications within 90 Days
  • Enter Domain Name for SSL Configuration.
  • Select 2 to redirect HTTP traffic to HTTPS
  • Restart Apache

Restart Apache

sudo /etc/init.d/apache2 restart
Setup WordPress On Google Cloud. Restart Apache
Apache will Restart after the command is executed.

Remember Pages/Posts may return 404 Error after deploying SSL on your WordPress Instance. It's common and in my experience one of the best things that can happen because you get to learn throughout the process as a beginner. Learn how you can fix 404 Error by clicking here.

Configure Certbot to Auto-Renew LetsEncrypt SSL.

Now that we have Setup LetsEncrypt SSL, we need to configure Certbot Auto-Renew script to ensure that our Website always redirects to HTTPS.

  Steps of Configuration:

We have deployed Certbot in the home directory, Lets, go back to Terminal and locate Certbot-Auto Package in Certbot folder.

ls

cd certbot

If you have downloaded the certbot-auto package to a different directory, it is important to locate it. If you cannot locate the certbot-auto package, you can re-download the package by executing the following command:

wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto
Setup WordPress on Google Cloud. re-download Certbot Auto-Package
re-download Certbot Auto-package and verify that it has been installed properly by executing the ls command to view the package.

Now, we need to move a Certbot Auto-package file to LetsEncrypt directory by executing following command :

sudo mv certbot-auto /etc/letsencrypt/
Setup WordPress On Google Cloud. Move Certbot Auto-Package
Move Certbot Auto-package

Next, we need to edit Crontab file. You can open your crontab file by executing the following command.

sudo crontab -e
Setup WordPress On Google Cloud. Edit Crontab
Edit Crontab

At the bottom of your crontab file, you will enter a script which will tell your server to check for certificate renewals once per week and to automatically renew the certificates if they are about to expire.

 Copy Paste the following Command 

45 2 * * 6 cd /etc/letsencrypt/ && ./certbot-auto renew && /etc/init.d/apache2 restart
Setup WordPress On Google Cloud. To Edit the file, press i to insert  then : set paste to copy the command in file
Save & Exit. 

That's it!, thanks for making it to the end 🙂

Now that you've Setup WordPress On Google Cloud & Configured SSL, You don't need to worry about renewing SSL again! You can go ahead Boldly Say "Hello World" 

If you are working in the field of Cloud computing or interested to learn, i’ve got a practical read for you about getting certified from Google Cloud in 2019.

I've also got this Data Science newsletter that you might be into. I send a tiny email once or twice every quarter with some useful resource I've found. Don't worry, I hate spam as much as you. Feel free to subscribe. 

Introduction to Cloud Computing
Introduction to Cloud Computing