Google Cloud: Installing WordPress on Compute Engine and using Cloud SQL as Database

Share At:

Lab Overview:

In this lab, we will create a Compute Engine using a WordPress Startup script. There is another way where you can use WordPress Image to launch the instance but that could be an expensive approach. We have provided the startup script and way to connect to the Database.

Lab Details:

  1. This lab walks you through Installing WordPress on Compute engine using Startup Script.
  2. Make sure, you have completed the Compute Engine lab and Cloud SQL lab. This lab will directly jump on to building WordPress, and not get into the detail of Compute Engine. If you have not completed the previous labs, we recommend you complete the previous labs first.
  3. In this lab, we will use a Startup script to install WordPress, and then connect WordPress with Cloud SQL.

Lab Tasks:

  1. Login into GCP Console.
  2. Creating a Firewall Rule.
  3. Creating a Compute Engine using a Startup script.
  4. Creating a Cloud SQL Instance.
  5. Create a Cloud SQL Database.
  6. Configuring WordPress to connect with Cloud SQL
  7. Testing the WordPress Site

Creating a Firewall Rule:

  1. Click on the hamburger icon on the top left corner
  2. Select VPC network.
  3. Click on Firewall.
  4. Click on Create firewall rule

5. Enter the firewall rule name as http-allow.

6. Choose the network as default.

7. Enter priority number as 1000.

8. Choose direction as Ingress as we are allowing all incoming HTTP traffic.

9. Choose Allow as we want to allow the incoming traffic.

10. Choose target as all Instances in the network. Same rule will apply for all the instances in the network

11. Enter the Source IP range as which means Internet.

12. Enter the port as 80 and check TCP as we are allowing HTTP traffic, HTTP port is 80.

13. Click on create to create the firewall rule.

Creating a Compute Engine:

  1. Click on the hamburger icon on the top left corner
  2. Click on Compute Engine.
  3. Click on Create.
  4. Enter the name as wordpress-instance. Do not enter any other name, It is required to validate the lab.
  5. Keep the region to us-central1 and Zone as us-central1-a.
  6. Choose series as N1
  7. Choose the machine type n1-standard-1.

8. Click on the down arrow to expand more options.

9. Enter the Startup script provided in the Supporting Document name WordPress Script.

10. Click on Create.

11. Now, your instance is up and running.

12. Make a note of your External IP.[].

Creating a Cloud SQL Instance:

  1. Click on the hamburger icon on the top left corner.
  2. Click on SQL under the Database section

3. Click on Create Instance to create your database instance.

4. Choose your database engine as MySQL.

5. Enter instance id as wordpress-db-<your-title>. For e.g. If your title is dev then enter instance id as wordpress-db-dev.

6. Set any password for your root user and keep a note of it, It is required at a later stage.

7. Choose database version as MySQL 5.7

8. Select region as us-central1 and Any zone. Please note, User Interface might differ for you. You should choose an us-central1 region.

9. Click on show configuration options.

10. Select the machine type as lightweight and has 1 Core with 3.75 GB of memory.

11. Click on the dropdown to change the machine type as Lightweight and select 1 vCPU, 3.75 GB.

12. Change the Storage type by clicking the down arrow on the right side.

13. You can choose any storage type. In our case, we are choosing SSD and storage capacity as 10 GB.

14. Click on the down arrow in the Connectivity tab. Make sure Public IP is enabled.

15. Click on Add network to allow your WordPress instance to connect with your DB Instance.

16. Enter the name as wordpress-network.

17. Enter the Network IP as the External IP of your Compute Engine which you noted earlier.

18. Click on Done.

19. Click on Create Instance to finally create your DB Instance.

20. Make a note of the Public IP of your DB Instance. You can find it in the Cloud SQL Instance.[].

Creating a Google Cloud SQL Database:

  1. Once you create DB Instance, click on databases.

2. Click on Create Database.

3. Enter the database name as wp_db. Do not enter any other name.

4. Keep the character set as utf8 and Collation as Default Collation.

5. Click on create.

Configuring WordPress to connect with Cloud SQL:

  1. Click on the hamburger icon on the top left corner.
  2. Now Click on Compute Engine > VM instances.
  3. Copy the External IP of your Compute Engine and hit the URL.[].

4. You will see the configuration page for your WordPress. Choose the language and continue.

5. Read the instruction and click on Let’s go!.

6. Enter the database name which you created in the earlier steps.

7. Enter the username as root.

8. Enter the password which you choose while creating the DB Instance.

9. Enter the Public IP of your DB Instance which you noted earlier in the Database Host.

10. Enter the table prefix as wp_

11. Click Submit.

12. Done, You are now connected with your Database. Now, click on Run the installation to create a WordPress website.

13. Choose the Site title as Hello Whizlabs.

14. Enter any username. It is required to login to the wordpress admin panel. In our case we have chosen root.

15. Enter any Password. It is required to login to the wordpress admin panel.

16. Enter your email address.

17. Click on Install WordPress.

18. Enter the External IP of your Compute Engine in the URL.

19. You can view the Hello world! post from your WordPress website.

Completion and Conclusion:

  1. In this lab, you have created a Compute Engine with a Startup script to install WordPress.
  2. You have created a SQL Instance and Database.
  3. You have configured WordPress to connect with Cloud SQL Database.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
binance sign up
2 days ago

I don’t think the title of your enticle matches the content lol. Just kidding, mainly because I had some doubts after reading the enticle.

gate coin
6 days ago

I am a student of BAK College. The recent paper competition gave me a lot of headaches, and I checked a lot of information. Finally, after reading your article, it suddenly dawned on me that I can still have such an idea. grateful. But I still have some questions, hope you can help me. türkiye
21 days ago

Your article made me suddenly realize that I am writing a thesis on After reading your article, I have a different way of thinking, thank you. However, I still have some doubts, can you help me? Thanks.

Back To Top

Contact Us