WordPress is an open-source content management system (CMS) written in PHP which enables the creation of attractive websites without any coding knowledge. As your website grows and gains more visitors, any downtime or slow-down leads to poor experience and may incur losses. This calls to employ a more reliable hosting solution, and Google Cloud Platform (GCP) is one of the best options available for the same. GCP provides multiple compute services like Compute Engine, Kubernetes Engine, App Engine, Cloud Run, etc. to deploy applications.
This blog post explains how to leverage these services to deploy the WordPress application on GCP. WordPress utilizes MySQL database to store data related to the posts, comments, and sites along with the local filesystem to store themes, plugins, uploads, etc. Hence, it heavily relies on the local filesystem to store the data.
What Is Cloud Hosting?
Cloud hosting is akin to any other hosting service that provides you with storage, resources, and a control panel to manage the website. The key differentiator between cloud and other hosting is in the infrastructure. Cloud computing uses multiple servers arranged in clusters that allow you to host files on multiple devices simultaneously. These files can be fetched from either of the servers that are part of the cloud.
Hence, cloud hosting offers unmatched advantages over other web hosting services. The primary benefits that Google Cloud offers are:
Manage traffic surges: When a website experiences a spike in the number of visitors, GCP uses dynamic scaling and adds additional bandwidth, managing the load seamlessly.
Reduced downtime: As GCP is a network of servers, the website files are not limited to a single server, which improves the uptime as well as the visitor experience.
Let’s look at each compute offering provided by GCP and analyze their benefits.
App Engine
App Engine is a fully managed serverless compute service which allows the deployment of web applications. Load balancing and scaling of the application are completely handled by GCP.
But deploying WordPress on an app engine is not a good option for the following reasons:
- App Engine file system is read-only so plugins won't work if it uses a filesystem to write the data.
- Updating theme / plugin / WordPress core can't be done from WordPress admin UI so they need to be performed by cloning the source code and updating them using commands. After that, you again need to deploy the code to App Engine to make it work.
- Since App Engine standard scales down to zero when there is no traffic, any file that is dynamically generated by plugins is deleted. However, this issue won't occur in the case of App Engine flex as there is always a minimum of one running instance.
- There is no way to mount cloud filestore instances.
Cloud Run
Cloud Run is a fully managed serverless container service where, similar to an app engine, the load balancing and scaling of the containers is completely handled by GCP. However, due to the stateless nature of the containers, it faces the same WordPress deployment issues as the App Engine.
Compute Engine
GCP recommends deploying the WordPress application on the single compute engine instance using GCP marketplace. However, when it comes to scaling the application, WordPress plugins/themes/uploads need to be shared across multiple instances. Same persistent disks cannot be attached to the multiple instances in ReadWriteMany mode. So this problem can be solved by mounting a cloud filestore instance on multiple compute engine instances.
This approach solves all the WordPress deployment issues while providing scalability but has some drawbacks:
- Compute Engine is the most unmanaged compute service as compared to other services as the customer needs to do OS patching.
- Cloud filestore is an expensive service and it charges a minimum of 1TiB of storage so even if the WordPress files consume 1 MiB, it will still charge for 1TiB of storage provisioned.
GKE Standard with Persistent Disk as File Storage
In this approach, a single persistent disk can be used to store WordPress themes/plugins instead of using a cloud filestore instance. However, it introduces the scaling problem as a single persistent disk cannot be attached to multiple WordPress pods in ReadWriteMode. So instead of directly mounting the WordPress pod to the persistent disk, the persistent disk can be mounted to the NFS deployment with a single replica and the NFS deployment can be mounted to WordPress pods.
This approach has some pros and cons as follows:
Pros:
- This allows scaling of WordPress pods as they are connected to the NFS deployment.
- A better option than the compute engine as it uses the persistent disk to store the files instead of the filestore which saves cost.
Cons:
- NFS deployment cannot be scaled as only one replica can be attached to the persistent disk in ReadWriteMany mode. So there is a scaling bottleneck at the NFS deployment.
- This approach cannot be utilized in the GKE autopilot cluster as the NFS deployment requires privileged pods, which are not allowed in the autopilot cluster.
GKE Autopilot with Filestore as File Storage
In this approach, WordPress is deployed on the GKE autopilot cluster along with a cloud filestore to store the WordPress files. There are some pros and cons of this approach.
Pros:
- This approach is the most managed as the GKE autopilot clusters are fully managed by GCP along with Node upgrade, repairs, maintenance. So there is no operational cost associated with it.
Cons:
- It is an expensive option as compared to the other options as the GKE autopilot charges for the pod usage.
For most of the sites with moderate site traffic, GKE standard with persistent disk as file storage option should be ideal as it is cost-effective along with the flexibility. If the user does not want any operational complexity, then GKE autopilot with filestore as file storage should be the best option.
Cloud hosting provides an effortless hosting solution with the guaranteed uptime, stability, speed, and performance. The ease of using it makes GCP a preferred choice.
To learn more about improving and modernizing your IT infrastructure, get in touch with our experts.