With the release of Google App Engine SDK version 1.8.5 it is now possible to run WordPress as a module instead of being the default module on appengine. This is a really powerful thing for SEO purposes. Let’s say for example that you’ve written your web application in Python and have it running at www.myapp.com
Now conventionally if you’d want to run a blog using WordPress you’d have to create a subdomain and make it something like blog.myapp.com because WordPress is written in PHP which means you’d need a separate runtime altogether.
That solution breaks down your domain’s SEO juice. How about instead you run the WordPress blog as a module under www.myapp.com/blog. Now that’s the power of Google App Engine (GAE) and what we can now do starting at version 1.8.5.
Beware, there are a few rough edges at the moment. But the talented team at Google is constantly improving the platform.
As you follow the steps below, please note the following conventions:
- <application_id> is your Application Identifier on Google App Engine.
Step 1) Create the Config Files
You’ll need to create 2 configuration files. dispatch.yaml and wordpress.yaml
The dispatch.yaml file determines which URL requests are sent to which module. In this case we’ll have the default module (configured by app.yaml) and the wordpress module (configured by wordpress.yaml)
The file should look like this:
- url: "*/"
- url: "*/blog*"
Like we mentioned you also need a file called wordpress.yaml which defines your wordpress blog module.
- url: /blog/(.*\.(htm$|html$|css$|js$))
- url: /blog/wp-content/(.*\.(ico$|jpg$|png$|gif$))
- url: /blog/(.*\.(ico$|jpg$|png$|gif$))
- url: /blog/wp-admin/(.+)
- url: /blog/wp-admin/
- url: /blog/wp-login.php
- url: /blog/wp-cron.php
- url: /blog/xmlrpc.php
- url: /blog(.+)?/?
Step 2) Install WordPress
Please follow the steps at https://developers.google.com/appengine/articles/wordpress but skip the app.yaml instructions.
Note that to run WordPress in the SDK you can run one of the following commands:
$ dev_appserver.py wordpress.yaml
This will make WordPress run under http://localhost:8080
$ dev_appserver.py dispatch.yaml app.yaml wordpress.yaml
This will make WordPress run under http://localhost:8080/blog using the dispatch routing configuration.
Step 3) Deploy to Cloud
I’m expecting that you followed the instructions linked to above and created your Cloud SQL database. Note that you can’t use your own MySQL server you have to use Cloud SQL when running PHP on App Engine.
When running locally using the SDK you have to use your own MySQL server for testing.
Now the deployment is what can be a little tricky. You have to specifically update the dispatch file using the appcfg.py command. And then update the rest of the app as well.
Also due to a current bug you cannot use the git push to deploy feature anymore because of the dispatch.yaml file.
So to deploy your app run the following 2 commands assuming you’re in the main app directory.
$ appcfg.py update_dispatch ./
$ appcfg.py update app.yaml wordpress.yaml
And once that’s done your app will be live and WordPress should be running at http://<application_id>.appspot.com/blog
Step 4) Custom Domain Fix
Due to another bug that Google is working on, in order for image uploads to work you cannot use your custom domain when using WordPress admin (wp-admin) to create blog posts, pages, etc.
The workaround for this is to adjust a couple settings in WordPress under General.
WordPress Address (URL) should be set to http://<application_id>.appspot.com/blog
Site Address (URL) should be set to http://www.myapp.com/blog (where www.myapp.com is of course whatever domain you are running)
Hope you enjoyed this how-to! Now have fun with App Engine.