Create wordpress website in Google Cloud Platform (GCP)

Senthil M Baskaran
5 min readFeb 3, 2021

WordPress is a popular content management tool. There are many providers (GoDaddy, NameCheap) who helps to buy domain and provide an option to host your website as well.

So why do we need to deploy wordpress in GCP (or AWS/Azure)?

There are various reasons:

  • You may wanted to control where the data stored due to regulation
  • Wanted to provide high availability as some providers can’t give you SLA for HA
  • Scaling your site is under your control
  • Ability to control cost when your business grows drastically

In this post I will share my experience how I managed to create wordpress in GCP and what are the options I considered

AWS vs GCP vs Azure?

When I decided to deploy the wordpress I assess which Cloud Provider is good for Demo purpose (or very light usage).

  • Azure have limitation on free credits. So I dropped the option
  • AWS have one year free option and I can use t2.micro. Definitely good option
  • GCP also equally good to AWS. I chose GCP as I have vast experience in AWS and wanted to try in GCP to keep up my skills

Deployment Model

GCP offers multiple deployment model such as Google Compute Engine (GCE), Google Kubernetes Engine (GKE) and Google App Engine (GAE)

Details can be found here

  • GCE — An easy and cost effective option just for Demo purpose
  • GKE — If you would like to deploy wordpress for SME or corporate then this would be the best option. Maintaining the application is easy. I didn’t choose the option as I have to deploy Cloud SQL separately
  • GAE: Best Serverless option and easy to maintain as well. Just that you won’t get fine grained control which you get it from GKE

With that said, let’s go and create our first WordPress website in GCP.

How to Deploy WordPress website in GCP?

Objectives:

  • Of course, the first objective is WordPress Website accessible via Internet
  • Website accessible via HTTPS
  • Sending Email

Pre-requisites

  1. Google Cloud Platform Account

Steps

Step1: Login to your GCP console
Step2: Register a domain and configure DNS

  • Since I am Cloud agnostic guy, I prefer to keep my domain at Non Cloud providers such as GoDaddy, namecheap. I am using namecheap
  • Initially I use GCP DNS and when I tried to configure MX records of namecheap, it throws en error. So I decided to use namecheap DNS server

Step3: Deploy a wordpress in GCE: WordPress is available in GCP Marketplace (Link)

Step4: Click Launch and fill up the values. I have attached some screenshot for a guidance

Step5: Please note down Admin URL and Site URL and other details. Either screenshot or copy to TextEditor.

Step6: Navigate Admin URL. And use your ‘WordPress Admin User’ and ‘Password’ to login.

With this WordPress site is ready to use. We can setup DNS forwarding to this IP. But not only that, we will also configure SSL and setup DNS together

Step7: Install certbot which will eventually manage LetsEncrypt certificate.

Login to GCE. I clicked ‘SSH’ and it connected to the ‘wp-wordpress-vm’. Run the following commands:

sudo apt install git -y

sudo git clone https://github.com/certbot/certbot.git

cd certbot

./certbot-auto

Do you want to continue? Y

Email address: <your email>

(A) agree xxxx: A

Some offer: N

Enter your domain name: cloud-withus.com www.cloud-withus.com

….

(Note: You will get an error let’s fix it)

Step8: To solve ‘Authorization error’. Let’s add [CAA] record and two [A] records in DNS Host zone. I did it in NameCheap->Domain List -> Manage DNS -> Advance DNS. You can do it GCP DNS, AWS Route53 Hosted Zone or where you maintain DNS service

Step9: Once done, come back to VM and run the command

./certbot-auto

(Note: You will then refill and fill the additional questions)

‘Which Virtual host to use”: Choose 2

You should get below message

Step10: Hopefully, this is the last step. Goto your WP-Admin portal (i.e. http://public-ip/wp-admin and update ‘WordPress Address (URL)’ and ‘Site Address (URL) with the https://www.yourdomain.xxx

Last Step: I thought Step10 was the last and realized after some days that I forgot to mention how I configure email.

My email provider is still “privateemail” (namecheap), they offered 3 months free usage and after 3rd month, they charge low. G-Suite will be second my choice once my website becomes popular. I used Office-365, its awesome, but bit costly.

Anyway, let’s go to the business. I downloaded WP Mail SMTP plugin and configured the settings. Most of the parameters are easy to fill in, but following is important to remember :


Mailer: I choose Other as my email provider is “privateemail”
SMTP host: mail.privateemail.com
Encryption: 465

That’s it and thank you for reading…

Conclusion

It was really fun, as I built my dream website (www.cloud-withus.com) in few days. WordPress indeed an easy to use and developer friendly. Configuring in GCE wasn’t hard. For sure, I will move to GKE based deployment in future.

Disclaimer: I am not a wordpress expert or GCP DevOps side. If you think I can do better, kindly suggest your idea in the comments or ask any clarifications in the comments. Let’s grow together

--

--