For today's blog entry we've got Drupal going on GAE. GAE is a lot different from a typical environment Drupal runs on. What does this setup entail? 

For starters, you will need to familiarize yourself with the basic Cloud Platform Services from Google and how they interact to run Drupal. Php is still a new language for GAE and there are certain limitation and constraints that must be worked around to make Drupal work on this platform. More on that later, for now let's cover what Google services are going to be needed.

  • Google App Engine (Php edition - will run the Drupal code)
  • Google Cloud SQL (Mysql db - persistance layer)
  • Google Cloud Storage (file storage)

If you're not familiar with how to do a basic app development and deployment for GAE you'll need to go through the tutorial. Since Drupal development uses Php you should do that one, however if you've done this before for Python or Java you may choose to skip it.

https://developers.google.com/appengine/docs/php/gettingstarted/introduction

Now on to configuring the base services.

  • navigate to cloud.google.com and log in.
  • create a project
  • enable billing (there are Free limits for each of the Google services but you will need to provide a valid form of payment in case you exceed the free limits)
  • enable Google Cloud Storage (via cloud.google.com)
  • create a storage bucket
  • download and configure gsutil (https://developers.google.com/storage/docs/gsutil_install)
    • 'gsutil config' and follow instructions. Once you get 'gsutil ls gs://' to work and you see the bucket you created continue to the next step.
  • create a Google SQL Instance (via cloud.google.com)
    • be sure to set the location preferences to 'Follow GAE App'
    • See 'Access Control' tab and request an IP for your instance
    • set root password
    • set Authorized Networks to your home or office IP for testing

At this point you should be able to connect to your cloud mysql instance via the standard mysql command line client.

For help on using a mysql command line client w/ Google see: https://developers.google.com/cloud-sql/docs/mysql-client

Setting up Drupal dev environment

Now on to the Drupal bits. This post (http://blog.boombatower.com/drupal-integration-module-google-app-engine) by @boombatower, it's a good overview of what needed to be changed in Drupal to make it work on GAE.  

To make things easier you can download an entire release that's already been patched and google_appengine module already packaged. For future Drupal releases you will need to patch the latest code yourself but for our purposes this packaged version will do nicely.
https://github.com/boombatower/drupal-appengine/releases/tag/7.x-appengine-full-1.0

Next we go through almost standard Drupal installation procedures.

Let's say we downloaded and unpackaged the patched Drupal to directory called drupal_gae .

It may be helpful to read and roughly follow this guide (drupal_gae/sites/all/modules/google_appengine/README.txt) that comes with the google_appengine module.  Some steps were covered above so skip them as needed.  Next you need to:

  • create your local db, add a user, set permssions etc.
  • configure your settings.php (as per the google_appengine/README.txt)
  • run the AppEngine dev server: dev_appserver.py drupal_gae
  • navigate to localhost:8080/install.php

You may see a PDO/SQL error. Fix it by setting the mysql socket in drupal_gae/php.ini and set the local mysql socket.  

pdo_mysql.default_socket=/YOUR-PATH-TO/mysqld.sock
mysql.default_socket = /YOUR-PATH-TO/mysqld.sock
mysqli.default_socket = /YOUR-PATH-TO/mysqld.sock

In the same file, also set your default storage bucket.

google_app_engine.allow_include_gs_buckets = "YOUR_DEFAULT_GCS_BUCKET"

At this point, you should be able:

  • to proceed with normal installation
  • configure the google_appengine module


Deployment to GAE

Dump mysql and import it on your GCS. Standard command line interface is the simplest here.

  • mysqldump -uroot -pYOURPASS drupal_gae1 >drupal_gae1.local.sql
  • mysql --host=CLOUDSQL-IP --user=root --password=YOURPASS drupal_gae1 <drupal_gae1.local.sql
  • Create a new non-root user for your Drupal installation on your Cloud SQL instanct
  • give it full permissions for your drupal db and execute 'flush privileges' in mysql
  • update the appropriate section of settings.php (you'll need db username, password and unix_socket for your cloud sql instance)
  • Edit app.yaml and change 'application: drupal' to 'application: YOUR-APP-ID'

At this point you should be ready to upload your full Drupal installation to GAE.

run appcfg.py update ./gae_drupal


Now go to YOUR-APP-ID.appspot.com and see if your Drupal site comes up.
You may see an error similar to this
PDOException: SQLSTATE[HY000] [1045] user 'YOUR-DB-USERID'@'localhost' .... in lock_may_be_available()

You will be able to connect to your instance with a standard mysql client using root and YOUR-DB-PASSWD but when Drupal tries to connect from GAE it fails with this error.
At first glance you may not see anything wrong with your mysql.user table but there is.  This is a straight permissions issue as it turns out.

  • make sure all the permissions are granted for 'YOUR-DB-USERID'@'localhost'.
  • make sure the PASSWORD IS SET for 'YOUR-DB-USERID'@'localhost'

You can use your root mysql login to achieve this. Be sure to 'flush privileges' when you're done.
At this point, refresh your site. You should see the standard Drupal homepage.

 

Drupal on GAE

 

I should also mention that Google provides Push-to-Deploy functionality but unfortunately I didn't get a chance to play with it yet. You can read more about it here:  https://developers.google.com/appengine/docs/push-to-deploy

Remember that you also get a detailed dashboard with GAE that tells you number of requests, errors, latency, and all sorts of other interesting stats about the performance of your app. You also get a Memcache viewer and quick ability to reset it. Overall it's a compelling offering.

Big thanks to @boombatower for providing a huge shortcut to getting this Drupal deployment on GAE going.
Hope this helps save you some time troubleshooting if you're venturing into the GAE world with Drupal.

- See more at: http://www.appnovation.com/blog/drupal-setup-google-app-engine#sthash.JYC1uSqy.dpuf

Read Next

The benefits of Scalable Vector Graphics (SVG)

23 December, 2013|3 min