Google App Engine for WordPress

Running WordPress in Google App Engine

At the Google I/O Developer Conference earlier this year, PHP, the fourth language runtime on Google App Engine was added in Limited Preview. Last Tuesday Google moved to Preview, making PHP on App Engine available for everyone immediately. It is now no longer necessary to whitelist your application for deployment.

Google App Engine is a (cloud computing) platform as a service (PaaS) that uses familiar technologies to build and host applications on the same infrastructure that powers Google’s applications with a 99.95% SLA. Whether you get huge traffic spikes or have lower traffic periods, App Engine scales your instances up and down automatically.

I had my first hands on experience with cloud computing as a developer in 2009 and then wrote an article for German T3N magazine about hosting Magento on Amazon EC2. Amazon Elastic Compute Cloud also delivers scalable compute capacity in the cloud, but Google App Engine is «abstracting» this still further so that you neither actually have to care about the underlying operating system, nor the web or database server. You just set up your PHP application and everything else is dealt with by App Engine. Isn’t that nice?

Running Magento in Google App Engine?

So after reading the news about App Engine moving from Limited Preview to Preview I thought it’s about time to play with it. First I thought about Magento and found the Github repository Magento-GAE by Magento core developer Kirill Morozov, which is an extension providing compatibility with Google App Engine. As there are quite some limitations though, e.g. because of the 10’000 files limit (Magento has over 13’000 files) I was a little bit discouraged at first, but then found an article from the Google App Engine team itself about running WordPress in App Engine. So here we go.

WordPress Hosting on Google App Engine

Installing WordPress on your Development Environment

The before mentioned article describes everything very clearly, but as I’m using MAMP on OS X for local development I wanted to use MAMP’s MySQL installation instead of installing it once more. After starting up my Development Server and pointing it to my application I was able to launch the WordPress installer and get to the page where you enter your database connection details, but using localhost or 127.0.0.1 as database host returned an

Error establishing a database connection

For debugging I left the WordPress installer and created a separate test app in App Engine using the following PHP code.

$link = mysql_connect('localhost', 'root', 'root');
if(!$link) {
    die('Could not connect: ' . mysql_error());
}else{
   mysql_close($link);
   echo 'Connected successfully and everything seems fine .... Checking MySQLi Installation<br><br>';
   if(function_exists('mysqli_connect')) {
     echo 'MySQLi is Installed :S';
   }else{
     echo 'Oops. You need to reconfigure Your PHP Installation to Include MySQLi';
   }
}

When I ran that script I got the following error:

Warning: mysql_connect(): No such file or directory in /Applications/MAMP/htdocs/google-app-engine-test/test-app/main.php on line 2
Could not connect: No such file or directory

So after doing some reading on Stackoverflow I figured that App Engine must be looking for the mysql.sock file in the wrong place. By directly connecting to MAMP’s MySQL socket located at  /Applications/MAMP/tmp/mysql/mysql.sock I was then able to successfully establish the database connection.

$link = mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');

I could now go back to the WordPress installer and use :/Applications/MAMP/tmp/mysql/mysql.sock (don’t forget the colon!) as the database host, but the more elegant solution is to create a symlink in the place where App Engine is looking for the MySQL socket file like so:

cd /tmp
ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock

So now we’re ready to continue with step 6 of the other article: Set up your Cloud SQL instance.

 

After making your WordPress application Cloud SQL aware you can then finally deploy it to App Engine either with the appcfg.py utility or by using Git Push-to-Deploy. Because of security reasons it is not possible to install WordPress plugins directly on your App Engine instance. You always have to either deploy through appcfg.py or Push-to-Deploy. Although App Engine guarantees that the deployment of new app code is always complete and a partial update can never happen, in rare cases it is possible that a deployment request can time out or fail which was the case with my very first Push-to-Deploy.

Here’s my outpout of git push appengine master

Counting objects: 1334, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1301/1301), done.
Writing objects: 100% (1334/1334), 5.85 MiB | 40 KiB/s, done.
Total 1334 (delta 103), reused 0 (delta 0)
remote: Scanning pack: 100% (1334/1334), done.
remote: Storing objects: 100% (1334/1334), done.
remote: Processing commits: 100% (3/3), done.
remote: Deploying...
remote: Created deployment: green-calling-365.clouddev.gaeTemplate-d981b975f1ecaa6d.deployment_1381669514627
remote: Created deployment: green-calling-365.clouddev.gaeTemplate-d981b975f1ecaa6d.deployment_1381669514627
remote: Created deployment: green-calling-365.clouddev.gaeTemplate-d981b975f1ecaa6d.deployment_1381669514627
remote: Timeout.
To https://code.google.com/id/XwisMvywdlv/
 * [new branch]      master -> master

I therefore had to fall back on appcfg.py to deploy my changes. Someone on Stackoverflow confirmed that he had timeouts in 1 out of 5 cases, so this feature is maybe not ready yet. But also without it, I like the Google App Engine approach very much and will seriously consider it for scalable WordPress hosting.

1 Kommentar zu «Running WordPress in Google App Engine»

  1. The one thing that can be a bit annoying is that you can not install themes and plugins right from the WP Admin while hosting on the App Engine and have to maintain a local copy of the WP website.

    I am from Cloudways and we have recently integrated Google Compute Engine into our platform with an easy UI to launch a GCE instance and install WordPress and WordPress multisites.

    The advantage of GCE through our platform is that WordPress websites can be managed and customized online anything can be installed and backups are automated with many other features. here are details: http://www.cloudways.com/blog/wordpress-on-google-cloud/

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert