How to Migrate your WordPress site from Managed Hosting to Google Cloud Platform

Moving your WordPress site from a Managed Hosting Provider to Google Cloud Platform is a great way to save money, while at the same time adding reliability, and reducing the overall load time of your website.

Why migrate to GCP

There are several reasons to use Google Cloud:

  • They are currently offering $300 free credits (or 1 year free)
  • It is extremely easy to scale up both your website, and your database
  • It is easy to do!

Backing up your existing  WordPress from your managed host

The first step in moving your site, is backing up your existing site.  I am not going to get into the specific details per managed provider, but the method is going to be generally the same.  For my guide, I am going to assume you have SSH access, but you could also follow the same general steps for PHP MyAdmin or FTP.  Check your providers documentation to determine the easiest method for your specific host.

Backing up your WordPress Directory

For this guide, I am assuming your WordPress root is /var/www/html.  If you are not sure, it is safe to assume the directory that contains wp-config.php or the correct index.php is your WordPress root.

locate wp-config.php or find /var/www/html -iname “wp-config.php”

SSH into web server

Tar your wordpress root:
cd  /var/www/html
sudo tar– cvpzf $HOME / wordpress_backup.tar.

Backing up your Database

Depending on your Web Host you may have built in access to CPanel or PHPMyAdmin.  Consult your managed host for specifics   ArcusIO also offers services to assist with moving your WordPress site to the cloud if you need help.

Method A:  From phpMyAdmin

Login yo your phpMyAdmin portal and backup your site.  Please consult your Managed Hosting Documentation, or one of the online guides available.

Dreamhost provides instructions that will be universal for CPanel/ PHPMyAdmin pages.

Method B:  From CLI

SSH into your server, and complete the instructions on the linked guide to backup your WordPress database.  It does assume that you know the name of your database, the username, and the password.

Copy your files over to your local computer

scp or FTP your files to your local computer.

$ scp – P 22 username@ domain: /home/ [username] / wordpress_backup.tar[path on local computer where to save file

You may find it easier to login to your site’s FTP server, and download the filess

Complete the same steps for your database backup file

Create your Google Console Trial Account

Sign up for the free trial for Google Console.  At the time of this writing, they were still offering the $300 Free Credit, or 1 year free trial

You will need to enter your address, company name, and billing information.  Your account will not automatically renew after the year or credit is up.

You are ready to begin using Google Cloud Services!

Creating your first project

  1. From the Google Console, create your first project that will be used for your WordPress site.
  2. Name your Project, in our example we named it myfirstwordpress.  Note, you cannot change this later so choose wisely.
  • It will take a few minutes for Google Console to create your first project.

Tip:  From the Google Console, you can pin the items you will be using most frequently.  I like to pin Compute Engine, SQL, VPC network, Logging, and Billing

Create the Static IP for your WebServer

Use the steps below to create the external static IP address that will be used for your public facing external IP address.  You will need to follow the steps with your domain registrar to repoint your DNS records to the new IP address for Google Cloud.

  1.  From Google Console, Select “VPC Network” and then “External IP Addresses”
    • Grab a coffee or go get a drink, it will take a minute to populate in the console.  O
  2. Once it loads, click “Reserve a static IP address”
    • Name the static IP address you will use, I called mine “webserver”
    • I use the defaults, including Premium Network Service tier, IPv4 and regional
    • For the region, use the region that will be closest to your users or intended market.  For mine, I use us-east1
    • You do not need to attach it for now, we will do this when we are creating the Compute Engine VM instance
    • Click Reserve to save your changes

Create the Compute Engine instance

  1. In Google Cloud engine, navigate to Compute Engine and then “VM instances”
  2. Once it populates, click “Create” to start creating your instance.
    • Select a name for your VM Instance, I named mine webserver, you will not be able to change this later.
    • Select the same Region as your External IP
    • Pick any of the zones you have available
    • For the Machine type, this will depend based on the amount of traffic your site generates.  For most sites, 1 V CPU and 3.7 GB should be plenty.  You can always stop your Instance and scale this up later if you need a more powerful server.
    • For the Boot Disk, my distro will be Ubuntu 16.04 LTS.  The rest of my tutorial will assume Ubuntu 16.04
      • Select “Standard Persistent” under Boot Disk Type, and 40 GB should be plenty, however create it bigger if you believe you will need more.
    • You can leave the defaults for Identity and API Acccess
    • Under Firewall, select “Allow HTTP traffic” and “Allow HTTPS traffic”
    • For network tags, enter “webserver” you can use this too easily create new firewall rules if needed later.  For example, to enable monitoring of services.
    • Click the “Management, disks, networking, and SSH Keys” link
      • Under Network Interfaces, click the edit icon
      • Under External IP, select the External IP you created previously.
      • You can leave the rest of the default options
    • Click “create”
      • Grab more coffee, or take a bathroom take.  This will take a few minutes.

Create the SQL Database

  1. In Google Console, select SQL
  2. Click “Create instance” to create your SQL server
  3. In my example, I will use MySQL and 2nd Generation
  4. Select “Configure MySQL Production”
    • Create an instance ID, I named my “myfirstwordpresssql”
    • Set a root password
    • Select the same region you chose for your Compute Engine VM Instance
    • Leave Enable Backups and Failover Replica defaults enabled
  5. Under “Authorized Networks” click “Add Network”
    • Enter your External IP address from previous steps in CIDR notation.  For a single host, this means you add /32 after the IP

Set maintenance schedule, I usually use Sundays at 4AM.

  1. Click Create to Create your SQL Instance
    • Get moar coffee (you might be pretty caffeinated by now)

Create Storage Buckets

Create storage buckets you will use to restore your wordpress root, and backed up databases from previous steps.

  1. Select Storage under the Google Cloud Console
  2. Click Create Bucket
    • Name your bucket, the rest of the defaults will be fine.
    • It’s slightly cheaper if you put your storage bucket in the same region as your SQL instance and Compute Engine VM Instance
  3. Upload the tar with your websites files, and the SQL backup you create from earlier steps.

Restore the database

  1. From the Google Console, navigate to the SQL Instance you created previously and select “Databases” from the management window
  2. Click “Create Database” and recreate the same name of the database you backed up previously.
    • If you’re not sure, you may be able to get the name of the database from your wp-config.php file
    • Leave the defaults
  3. Click “Import” to import your SQL file from your storage bucket.
    • You will receive an unknown error if the name changes
    • If you run into issues, try specifying the database name under “Advanced Options”

Create the user for your SQL database to be used with WordPress

  1. Navigate your SQL instance
  2. Click the “Users” tab
  3. Create the username and password, for security restrict the host to the same value you used for your database.

Upload your webserver files from your bucket to your Compute Engine Instance

  1. Navigate to your storage buckets browser
  2. Under the tar file you uploaded earlier, click “Share Publically” and then copy and paste the link and keep for future steps.

Configure your Compute Engine instance, install services

  1.  Navigate to your Compute Engine instance, click on “SSH” and Open in new browser window
  2. Install necessary services:sudo apt-get install php7.0 apache2 php-mysql mysql-client -y
  3. Navigate to your webserver root and download your tar you recorded the public path to earlier cd /var/www/html ; wget [public path from bucket]
  4. Untar the file  sudo tar -xvpfz [file name of tar file]
  5. Remove the index.html file sudo mv index.html index.html.old
  6. Enable apache2 service sudo systemctl enable apache2.service
  7. Restart apache2 service sudo systemctl restart apache2.service
  8. Update the wp-config.php files with your new database or usernames, if different,  Change the host
    • sudo vim wp-config.php
      • DB_USERNAME and DB_PASSWORD are the ones you created for your SQL Instance Earlier
      • DB_HOST is the external IP of your database, which you can view from the SQL Management Console under your primary database under Primary IPv4 IP Address
      • Hint:  i in vim will take you into insert mode, and you and erase and change the values below
      • Hit ESC to exit insert mode, and wq! to save

Point your websites DNS entries to your new website, and you’re good to go!

  1. This is specific to your DNS registrar, but you will need to replace the IP address from your Managed Hosting Provider with the IP address for your Google Compute Engine.

That’s it!  Now, beginning this month, Google Chrome will warn your site’s users if you are still using http, and not https.

Next:  Secure your website with an SSL Certificate (https)

Comments are Closed