DEV Community

Cover image for WordPress Migration to Google Cloud Platform
Gilad David Maayan
Gilad David Maayan

Posted on • Updated on

WordPress Migration to Google Cloud Platform

While you can run WordPress on your own server, this requires ongoing maintenance work, and will make your website less reliable. Most website owners host their websites using hosting providers—these providers assume responsibility for maintenance, high availability, and ensuring the website runs at a required performance level.

Another option is to migrate to the cloud. Google Cloud Platform (GCP) is one of the big three cloud providers, and it provides a generous free plan that can let you run a WordPress site on a small server, free for a year.

Running WordPress on the cloud is a middle ground between managing your own server and full hosting. On the one hand, you will need technical expertise to set up and manage a virtual machine on GCP.

On the other hand, there is no need to purchase and maintain a server. Google assumes responsibility for uptime, high availability, and provides easy scalability if you need to upgrade your site to a bigger server or add more servers.

WordPress on the Cloud vs. Other Hosting Models

Let’s compare three methods you can use to host a WordPress site.

Hosting WordPress on-premises
Running your WordPress site on a local server you or your organization owns means you have complete control over the website, and also run on dedicated resources. However, you have full responsibility over maintenance, software updates, and security, and need to make sure your website remains up at all times.

Hosting WordPress using shared hosting
This is the cheapest hosting option, is the easiest to manage from a website owner’s perspective, and is effective for many websites. The hosting provider takes care of the server and usually provide security features and uptime guarantees.

The downside that your website will be hosted on the same server together with many other sites, which can lead to unpredictable performance. You are also exposed to cyber attacks or other issues affecting your neighbors on the server. This option is not suitable for large scale, high performance websites or those that cannot tolerate downtime.

Hosting WordPress using managed hosting
Managed hosting, also called virtual private server (VPS) hosting, gives you dedicated computing resources to run your WordPress site. This type of service is commonly hosted on a public cloud like Google Cloud Platform. However, the website owner is not aware of this, and works with the management interface offered by the hosting provider.

This model is suitable for websites with more stringent performance and uptime requirements, and providers usually provide more advanced management features, improved security and service level agreements (SLA).

Hosting WordPress in the public cloud
Hosting WordPress on a cloud like Google Cloud Platform gives you access to powerful capabilities of the cloud platform—such as automated scalability, high availability and replication across data centers, and a globally distributed infrastructure.

However, you will need the time and expertise to build the right configuration in the cloud, and you will need to take responsibility for achieving performance and uptime goals, using the tools offered by the cloud provider.

WordPress on the Cloud: Key Considerations

Here are a few things you should take into account as you consider whether cloud hosting is the right option for your WordPress site.

  • Technical expertise—operating on the cloud requires more technical expertise than running an on-premise server, and is much more difficult than using a hosting provider.
  • High availabilitymaking your website highly available, for example by replicating it across multiple availability zones or regions, is not trivial to achieve in a public cloud. There are also costs involved, because additional resources you use are billed by the hour. It is possible to automate infrastructure changes, but this increases complexity even further.
  • Performance—to keep users happy, you need a high performance, well optimized website. Running WordPress directly on cloud resources can allow you to push performance to the max, by scaling up to meet any level of demand. This comes at a cost, because scaling up requires paying for more cloud resources. But cloud hosting will always beat traditional hosting in terms of performance, for large-scale or mission critical websites.
  • Migration—if your WordPress site has more than one server, or has external dependencies, it can be complex to migrate to the cloud. Take into account that any external dependency will require refactoring, and you need to consider whether to move the dependent system, for example a database, into the cloud as well.
  • Costs—public clouds like Google Cloud Platform have free plans that give you a basic configuration free for a year, and some services for free on an ongoing basis. However, take into account what will be the cost of running your website 24/7/365 after the free period ends—in many cases costs will be higher than with hosting providers.
  • Security—public clouds provide extensive security features, but you are responsible for implementing them (this is called a shared responsibility model). Security misconfigurations are common on the public cloud, and have led to catastrophic security breaches. Take care to configure security correctly, and remember that a small oversight can leave your cloud-based systems exposed and open to attack.

Migrate WordPress Website to Google Cloud Platform

You can migrate WordPress to Google Cloud Platform by following the steps below.

1. Create a free virtual machine
Create a Google Cloud Platform account and set up a free F1-micro virtual machine. See details of the GCP Free Tier.

2. Edit DNS records
Edit the DNS records for your website and reduce the time to live (TTL) to 330 seconds. This will reroute users quickly to the new server on Google Cloud. You should do this a few days before migration, because DNS propagation typically takes 1-2 days.

3. Google Cloud setup for WordPress
You can set up WordPress on either the Apache web server or the Nginx web server. Deploy an image on the virtual machine with the operating system of your choice (Ubuntu, Debian, etc.)

Under your operating system root, create a folder with your website name (e.g. mywebsite.com), and under it create two subfolders:

  • public—this will be the root directory of your website
  • logs—this folder will hold WordPress logs

4. Create a new DNS record in Cloud DNS
You now need to create a new DNS record in Google Cloud DNS (see documentation) with an A record pointing to the virtual machine's IP address. It is recommended to configure DNSSEC (secure DNS) to protect your domain name from DNS cache infection.

5. Display a message notifying about the migration
During your migration, you need to stop your WordPress instance to prevent it from modifying the database. In the meantime, show a “Down for maintenance” notice. An easy way to do this is to upload an index.html file to your root directory and serve it instead of index.php.

6. Remove MyISAM database engines
Check if your MySQL database uses the MyISAM database engine, which is not supported by Google Cloud. If so, you’ll need to remove it or replace it with InnoDB.

7. Back up the current WordPress instance
Backup your WordPress instance and the database and save them as files locally. You can then upload the database files to a Cloud Storage bucket, and import them into Cloud SQL, Google’s managed database service (see documentation). Copy the WordPress files into the public directory on the virtual machine.

8. Switch DNS
Make sure the database and WordPress instance are working correctly on the virtual machine. Then, update your DNS records and provide the records provided by Google Cloud. Keep in mind DNS queries are cached, so some users will continue to see your old website with the maintenance notice. However, before we reduced the TTL value in step 1, the switchover will happen relatively quickly.

Conclusion

In this article I explained the motivation for moving your website to Google Cloud Platform, and key considerations including the level of expertise needed, high availability, migration and security options. Finally, I provided an 8-step process for migrating WordPress to GCP:

  1. Creating a free machine
  2. Editing DNS records
  3. Setting up Google Cloud virtual machine for WordPress
  4. Creating a new DNS record in Cloud DNS
  5. Displaying a maintenance message
  6. Removing MyISAM database engines
  7. Backing up your existing WordPress instance
  8. Uploading it to GCP and switching DNS

I hope this will help you understand if true cloud hosting is right for your WordPress site, and if so, to successfully make the move.

Top comments (0)