Click here to Skip to main content
13,006,705 members (57,867 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 2 Jul 2014

Migrate WordPress to Google App Engine

, 2 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Migrate WordPress to Google App Engine

Why not run WordPress on Google App Engine? You will get performance and stability while only paying for the resources you actually use. Reading the official Google tutorial "Running WordPress in App Engine" gives you a fair idea what you are in for. But if you want to migrate a currently running site, then you have to do some tweaking. So here is a run down on how to do it!

1. Download All Data From Current Site

Download all files in the public HTML directory from you site. You also have to obtain a copy of your database. The way you do this depends on what your current ISP setup is. Please note that comments and other content added after this DB download will not be avalible in the new installation. Therefore it’s recommended that you take a fresh backup when you see that everything works as it’s supposed to.

2. Setup Local Environment

To be able to do this, you need four components installed on your local machine.

3. Setup Google App Engine Launcher

In the Google App Engine Launcher "File" menu, select “Create new application...

  • Application name” – Will be the Google App Engine identifier when you upload, don’t worry this can be changed later
  • "Parent Directory" - Where you will store the files locally
  • Runtime” – Select PHP
  • Delete the “main.php” file that is created in the folder
  • Copy all the contents you downloaded from your public HTML directory

4. Setup “app.yaml”

The "app.yaml" contains the configuration information for Google App Engine. The first line contains "application:", you will notice that this is the same as the "Application name" you selected in the previous step. Important to remember here is that this will be part of your web address if you don't use a custom domain, e.g., so in that case you will end up with

Next few rows is nothing you need to worry about: version, runtime, api_version and threadsafe you can leave as they are.

The handlers: on the other hand is really important to get the WordPress site working on Google App Engine. You should use this:

- url: /(.*\.(htm|html|css|js))$
static_files: \1
upload: .*\.(htm|html|css|js)$
application_readable: true

- url: /wp-content/(.*\.(ico|jpg|png|gif))$
static_files: wp-content/\1
upload: wp-content/.*\.(ico|jpg|png|gif)$
application_readable: true

- url: /(.*\.(ico|jpg|png|gif))$
static_files: \1
upload: .*\.(ico|jpg|png|gif)$

- url: /wp-admin/(.+)
script: wp-admin/\1
secure: always

- url: /wp-admin/
script: wp-admin/index.php
secure: always

- url: /wp-login.php
script: wp-login.php
secure: always

- url: /wp-cron.php
script: wp-cron.php
login: admin

- url: /xmlrpc.php
script: xmlrpc.php

- url: /wp-(.+).php
script: wp-\1.php

- url: /(.+)?/?
script: index.php

5. Setup “cron.yaml”

This file is for the cron jobs. This is the same as on Linux/Unix machines and replaces the timer jobs WordPress have on other platforms. This file should contain:

- description: wordpress cron tasks
url: /wp-cron.php
schedule: every 2 hours

6. Setup Local Database

So after installation of the MySQL software, start the MySQL Workbench. (There maybe some initial configuration wizards here, I already had it installed when I wrote the tutorial!)

  • Double click the "Local instance MySQL..."
  • If "Server Status" is "Stopped" then go to the "Server" menu and select "Startup/Shutdown", then click the "Start Server" button.
  • When server is "Running", click the "Data Import/Restore" in the left hand "Navigator" menu.
  • Select the "Import from Self-Contained File" radio button, then browse for the database backup/dump you downloaded in step one.
  • Under "Default Schema to be Imported To" click the "New..." button.
  • Name the schema something you will remember.
  • Click the "Start Import" button.
  • When the database is successfully imported, hit the little refresh icon next to "Schemas" in the left hand "Navigator" menu, now you should see your new database (or schema as it's called in MySQL).
  • Double click on you new database and then on "Tables", find the "wp_options" table, then right click and select "Select Rows - Limit 1000".
  • Find the row where the field “option_name” is “active_plugins” and delete it! (This is to disable all active plugins before we upload)
  • Find the rows where "option_name" is “siteurl” and “home” and set them to “http://localhost:portnumber”. The port number should correspond to the one in the applications "port" column in the Google App Engine Launcher application list.

NOTE: You can also run this query against the server to delete the "active_plugins" row:

DELETE FROM wp_options WHERE option_name = 'active_plugins';

7. Configure “wp-config.php”

Now you need to setup WordPress to access your database. This information is different between your local environment and the Google App Engine environment. I simply use an if statement to take care of that problem and save me the trouble of changing the wp-config.php file every time I update my site.

    if(isset($_SERVER['SERVER_SOFTWARE']) && 
      strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
        /** Google App Engine Settings */
        define('DB_NAME', 'hackviking_com');
        define('DB_USER', 'root');
        define('DB_PASSWORD', '');
        define('DB_HOST', ':/cloudsql/wp-hackviking-com:db');
        /** Local Settings */
        define('DB_NAME', 'hackviking_com');
        define('DB_USER', 'root');
        define('DB_PASSWORD', 'mylocaldbpassword');
        define('DB_HOST', 'localhost');

DB_NAME - Name of the database. Locally, it's the schema name you selected in step 6 when you imported your database. For the name used on Google App Engine, please see "Setup the "Google Cloud Platform."

  • DB_USER - Usually it's root locally if you haven't customized your setup. On Google App Engine, it's always root.
  • DB_PASSWORD - Password for the corresponding DB_USER. On Google App Engine, the password for root is always null due to access control being controlled on app level.
  • DB_HOST - On local environment, it's "localhost". On Google App Engine, please see "Setup the Google Cloud Platform."

8. Prepare Local Site for Upload

  • Run the site and login to the WordPress admin site, e.g. "http://localhost:<portnumber>/wp-admin".
  • Run all available updates, you will not be able to do this when the site is uploaded. To install plugins and updates, you have to do it locally and then reupload. Therefore, it’s a good idea to keep your local environment to be able to take care about this later on.
  • Delete all WordPress plugins that will not work on Google App Engine, it’s not easy to know before you try but a rule of thumb is that caching and minifying plugins won’t work.
  • Install WordPress plugins required for Google App Engine.
  • Google App Engine for WordPress
  • Memcache Object Cache
  • Batcache

9. Setup the "Google Cloud Platform"

  1. Log in and create a new project by clicking "Create Project". If the "Project ID" is available, that will automatically be the name of your Google App Engine instance and that name is part of your web address e.g. <projectID> NOTE: This cannot be changed later, if you are not happy with your url, you have to create a new project!
  2. To be able to run "Cloud SQL" needed for the MySQL implementation in WordPress, you have to enable billing for the project. In the projects overview, click your new project, go to "Billing & Settings" and click "Enable Billing". Fill out all the details for the billing and verify your payment option.
  3. Now, you can create the database for your system. In your project view, select "Storage" ->"Cloud SQL" -> "New Instance".
    • "Instance ID" - The name of your database. The name will be <projectID>:<InstanceID>.
    • "Tier" - Start out with "D0 - 128M RAM" and upgrade later if you need.
    • "Billing plan" - I prefer the "Per Use" when I start out.
    • "Preferred Location" - The logical choice is to select "Follow App Engine App".
    • "Assign IP Address" - Select "Assign IP Address", we need this later to upload our database!
    • "Authorized IP Address" - Your public IP address that you will use to access the database later. If you don't know visit
    • Click "Confirm" and the database will be set up. Go to "Access Control" and use the "Set root password" to set a password for the root account.
  4. Setup file storage for file uploads.
    • Before you can set this up, you need the "Service Account Name" for your Google App Engine instance. Easiest way to access this is to select "Compute" -> "App Engine" -> "Quota details" which will send you the Google App Engine dashboard. Then select "Application Settings" under "Administration" and copy the "Service Account Name".
    • From the project view, go to "Storage" -> "Cloud Storage" -> "Storage Browser" -> "New Bucket" and select a name for it. I like to use the same name as my "Project ID".
    • Then tick the box next to your new bucket and click "Bucket Permissions".
    • Under "Add another permission" select "User" in the drop down, enter the "Service Account Name" and select "Writer" as permission and then click "Add".

10. Upload Database

So now you have to get your database online. Start by creating a database backup of your local database. If you didn't authorize your IP address in step 9, follow these instructions to do so:

  1. Login to your Google Cloud Console.
  2. Select your project name.
  3. Click  "Storage" -> “Cloud SQL”.
  4. Select your instance name.
  5. Click “access control”.
  6. Click “request an IPaddress”.
  7. Click “add authorized network” and enter your public IP address. If you don’t know, visit
  8. Click “set root password” and set it to something you remember.
  9. Connect with MySQL workbench to the database instance you created in step 9 and import your database backup to a new schema.
  10. Go into the database and set the “siteurl” and “home” to <projectID>
  11. If the row “active_plugins” exists, delete it!
  12. NOTE: Don’t forget to disable the external access after you’re done! For security reasons and cost. It costs every hour it’s open.

11. Final WordPress Config & Deployment

Now you have to go back to step 7 and put the new configuration into the "wp-config.php" file. In step 4, we talked about app.yaml, now you need to update that file! The line saying application: should be updated with your project ID from step 9. When this is done, hit the "Deploy" button in Google App Engine Launcher to upload your site.

12. Config Site Online

Go to <projectID> and login with your admin account.

  • Enable plugins:
  • “Google App Engine for WordPress”
  • “Memcache”
  • “Batcache”

When this is done, go to "Settings" -> "App Engine" under "Upload Settings" you have "Bucket name" fill in the one you setup in step 9. This is for storing uploaded media files. Then enable your plugins one by one and test that the site is working. If you encounter issues with this, just enable external DB access again and remove the “active_plugins” row from the database.

12. Trouble Shooting

If you encounter issues with WordPress caching still enabled, then try the following:

  • Delete “advanced-cache.php
  • Delete “wp-cache-config.php
  • Delete “cache” folder from “wp-content” and “wp-includes
  • In “wp-config.php” set “WP_CACHE” to “false

Hope you liked this tutorial, if so please share it with others! Please tell me what you think in the comments below and give me any suggestions/requests you have! Stay tuned for more articles about WordPress and App Engine.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

I develop in C# on .Net platforms like MVC. Like to use jQuery to build rich interfaces. I also blog about development and snags I got and the solutions I found for them.

I also a full time CIO at a Swedish energy company. When there is time I do some part time consulting on cloud issues.

You may also be interested in...

Comments and Discussions

Questionall setup, kinda... Pin
Member 1220520613-Dec-15 19:08
memberMember 1220520613-Dec-15 19:08 
QuestionSQL Error Pin
nay1816-Jun-15 23:50
membernay1816-Jun-15 23:50 
AnswerRe: SQL Error Pin
Kristofer Kallsbo29-Jul-15 12:23
memberKristofer Kallsbo29-Jul-15 12:23 
QuestionHi Kristofer, I'd like to share my issue Pin
Member 114381868-Feb-15 22:55
memberMember 114381868-Feb-15 22:55 
AnswerRe: Hi Kristofer, I'd like to share my issue Pin
Kristofer Kallsbo29-Jul-15 12:25
memberKristofer Kallsbo29-Jul-15 12:25 
QuestionQuestion - 3. Setup Google App Engine Launcher Pin
Member 114337806-Feb-15 15:00
memberMember 114337806-Feb-15 15:00 
AnswerRe: Question - 3. Setup Google App Engine Launcher Pin
Kristofer Kallsbo29-Jul-15 12:22
memberKristofer Kallsbo29-Jul-15 12:22 
QuestionHow to set up local environment? Pin
Member 1093955110-Jul-14 22:29
memberMember 1093955110-Jul-14 22:29 
AnswerRe: How to set up local environment? Pin
Kristofer Kallsbo18-Jul-14 4:58
memberKristofer Kallsbo18-Jul-14 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170628.1 | Last Updated 2 Jul 2014
Article Copyright 2014 by Kristofer Kallsbo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid