Set up wordpress on GCP

1. Create a Google account.

2. Set up your cloud machine. Go to GCP console and apply for a free 90 days trial.

The wordpress website set from this note is very simple, so do not worry if the free trial has ended – the charge can be from free to a minimum amount.

On GCP, you can create multiple projects. I like to keep one project set for only one website, to make it clean. In the screen shot, you can see the project name for this website as “Knowledge Base”.

If you select the stack button on the upper left, you will see a lot of complicated modules. But don’t worry, the following 4 modules shown in the screen shot are the ONLY ones that you need. You can find them, can pin them to the top.

3. Set up your wordpress website. Go to Marketplace, and search for wordpress apps. Again, there will be many apps for it but don’t panic. Find this exact app named “WordPress” provided by Google Click to Deploy. It’s an official app from Google, with simple function and description. Click on the app.

Now, in order to comply with the free of charge policy for GCP, select the minimum options as the following screenshot.

Deployment Name: name it by yourself

  • Zone: us-xxxx-x (It MUST be somewhere in US)
  • Machine type: micro (1 shared vcpu) 0.6 GB memory, f1-micro
  • Administrator e-mail address: your Google account
  • Boot Disk: Standard Persistant Disk, 30GB

For other options, leave it as default. Mine default is shown as the screen shots. Wait until the procedure is automatically done, your wordpress website is ready.

You can check your wordpress website from “Compute Engine

4. (To be editted)


5. Change the website url into your own domain name. This is a tricky part so you need to be careful.

First, purchase a domain name from Google. If your country does not support this service, it’s OK. You can enter a random US address to finish the process with your credit card.

Second, set up DNS (domain name server). DNS is for the computer to convert your website IP address into your easy-to-remember domain name.

Go to VPC network – External IP addresses, select your website, and click on “reserve static address“.

Then go to Network services – Cloud DNS, click on “create zone“.

  • Zone Name: name it by yourself
  • DNS name: the domain name you just purchase, for my case it’s “classic-notes.com”

Not finished yet, now you have to go to the DNS zone you just created. If you check you record sets, you should see only type SOA and type NS records.

You need to ADD RECORD SET for Type A file. Shown as screenshot, only type in your website’s IP in IPv4 Address, don’t touch everything else.

Then you need to ADD RECORD SET for C Name file. Only type in your domain name (classic-notes.com in my case) in Canonical name, don’t touch everything else.

If you see a complete 4 records as screenshot, you have finished 1/3 of the entire procedure.

6. (continue to 5.) Noticed that for NS record shown in the screenshot, there are 4 addresses named after ns-cloud-c1 to 4. These addresses must go to your domain provider, so you can really finishing connecting your website IP address to your domain name. Go to Google domain, select your domain name, then go to DNS.

Use custom name servers, and add the 4 addresses named after ns-cloud-c1 to 4 that you just found in GCP webstie cloud DNS NS record. Don’t use the Google Domains name servers option, because I notice that there will be an error for unknown reason.

Then scroll down to the buttom of the DNS page, you will see Custom resource records. Add a Type A record with your IP address filled in IPv4 address, shown as the screen shot.

Now you are ready to proceed to the final stage.

7. (continue to 6.) In your wordpress admin panel, you can see from Settings – General, there are two spaces of WordPress Address (URL) and Site Address (URL), as if you can modify your website url easily.

You should modify the url now, but be aware, that your website will be temporarily NON-ACCESIBLE. Don’t panic for this result as we will solve it soon.

Go to your GCP console, select Virtual machines – VM instances, find your website and click on SSH button at the right.

You will then open a new window that looks like cmd, and seems to be very difficult to proceed. But actually, it’s much easier then you thought. We open this command window to manually modify a file called wp-config.php. First, we have to find the location of this file by entering:

sudo -i
sudo find / -name wp-config.php

Wait for a while, then the window shall return the location of this wp-config.php file. In my case, it’s /var/www/html/wp-config.php. Copy this location, then close the window.

Open the SSH window again by clicking SSH button. This time, enter:

sudo -i
nano /var/www/html/wp-config.php

This is what the window will return

Don’t affraid of the words in it. All you need to do is press ↓ button on your keyboard, to scroll down the screen. When you scroll down further, you will see a sentence of /*That’s all, stop editing! Happy publishing. */

Shown as the screenshot, above this sentence is exactly the place that you need to paste the following commands:

define(‘WP_SITEURL’,’http://yourdomain.com’);
define(‘WP_HOME’,’http://yourdomain.com’);

Change the yourdomain.com words in my code into your domain name. Keep the http:// words infront. After editing, press Ctrl+X on your keyboard, then press Y for confirming the modification, finally press Esc+D to save the result. (Press Esc+M instead if you are using an Apple Mac Book)

Now close all the windows, you should be able to access to your website with your own domain name after a while.

Leave a Reply

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