How to deploy WordPress site on Google Cloud Platform

Ritik Raj
6 min readOct 9, 2020

I am going to perform GCP Task-1, in this task, I am going to deploy a WordPress site and connect this site to MySQL server for the database.

Task-1)

1. Create multiple projects namely developer and production

2. Create a VPC network for both the projects

3. Create a link between both the VPC networks using VPC Peering

4. Create a Kubernetes Cluster in developer project and launch any web application with the Load balancer

5. Create a SQL server in the production project and create a database

6. Connect the SQL database to the web application launched in the Kubernetes cluster

So let’s starts with Step-1

Step-1) Create multiple projects namely developer and production

Step-2) Create a VPC network for both the projects

Now before going to create VPC we have to enable a compute engine API as shown below image.

creation of dev project VPC
creating a subnet

In the above image, we are creating a subnet so that every user from the outside can come inside or can access WordPress.

In the above image, dev vpc has been created successfully. Now the same steps are going to follow for creating a VPC in prodproject987.

prod subnet is created
Prod PVC has been created

Now as you can see in the above image, Prod VPC has been created successfully.

Step-3) Create a link between both the VPC networks using VPC Peering

Before going to create VPC Peering, first, we have to allow the ports from the FIrewall so that any user can access our WordPress.

Now we are going to create our own Firewall on both the projects so that in the future there will be no connectivity issue.

See the below images properly:-

Creating Firewall (allow all port)
Apply for Allow all Ports and source range is public world (0.0.0.0/0)
See the image, allow all firewall has been created

Now the same firewall we are going to create for another project.

Creating a firewall for another project
Attaching subnet
Firewall has been created successfully.

Now we are going to create VPC Peering, VPC Peering helps to connect both the VPC for private access.

Create Connection
Creating Peering Connection with another project

In the above image, as you can see the connection is inactive, it will be active when we create PVC peering to other projects also. See the below image.

Creating Peering Connnection to another project

As you can see we have successfully created VPC Peering.

Step-4) Create a Kubernetes Cluster in the developer project and launch any web application with the load balancer.

Now we are going to create a cluster, see the below image:-

Creating Cluster

Now we are going to launch the nodes in all 3 data centers as shown in the below image.

Launching nodes in al 3 data center

Now we are going to launch this cluster in our created VPC as shown in the below image.

Cluster launched in devvpc

Now cluster successfully launched as shown in the below image.

Cluster has been launched successfully

Now we are going to launch WordPress pod on our cluster using the Command line, for command-line access we need to give username and password as shown in the below image.

Copy the above image command and paste it on cmd.

Now we going to run some commands so that we can launch the pod, scale-out the pod, and expose the pod with LoadBalancer as shown in a below image.

Now use the external IP of the load balancer for opening WordPress.

Commands I used for 1) create deployment: kubectl create deployment mywordpress — image=wordpress.

2) For scaling deployment: kubectl scale deployment mywordpress — replicas=5

3) Expose the load balancer: kubectl expose deployment mywordpress — type=LoadBalancer — port=80

Note: WordPress has been launched successfully.

Step -5) Create a SQL server in the production project and create a database.

Now we are going to launch SQL instance for backend connectivity as shown in the below image.

Cloud sql instance

Now choose MYSQL as shown in the above image.

Now creating MySQL instances as shown in a below image.

Now Mysql instance has been initialized successfully as shown as below image.

Now to access the MySQL instance we have to add the network to allow the ports as shown in the below image.

In the above image, we are giving access to all the users of the public world.

Now we can create our own database as I am going to create “lwdb” database as shown in the below images.

The database has been created successfully.

Step-6) Connect the SQL database to the web application launched in the Kubernetes cluster

Now we are going to install WordPress as shown in the below image.

WordPress successfully installed.

WordPress has been launched successfully.

Note: The task of the Google Cloud Platform has been Completed.

--

--