WordPress

WordPress on Managed VMs (DEPRECATED)

This post is deprecated in favor of the new post.

We have just released a PHP docker image for App Engine Managed VMs. Please see the README file for how to use the image.

Managed VMs provides more flexible PHP runtime environment, compared to App Engine. Then running WordPress on App Engine should be now more straightforward than before. I’ve just successfully made it work, so I’ll show you how here.

Prerequisites

Preparation

First create a directory for deployment. Let’s say we’ll have wp-mvm directory.

$ mkdir wp-mvm
$ cd wp-mvm

Then add following few files in this directory.

app.yaml:

runtime: custom
vm: true

manual_scaling:
  instances: 1

app.yaml file is the main configuration file for App Engine Managed VMs. You can change the scaling settings if you want, but currently the plugins and themes installed on one server will not reflected to other servers, so I’m sticking with one single server now.

Dockerfile:

FROM gcr.io/php-mvm-a/php-nginx:latest

# The docker image will configure the document root according to
# this environment variable.
ENV DOCUMENT_ROOT /app/wordpress

# Allow direct installation of plugins and themes
RUN find /app/wordpress/wp-content -type d -exec chmod 0750 {} \;
RUN find /app/wordpress/wp-content -type f -exec chmod 0640 {} \;

nginx-app.conf:

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

location /_ah/health {
    return 200 'ok';
}

The entry for /_ah/health is for health checking.

php.ini:

suhosin.executor.func.blacklist=""

Because our image enables Suhosin and disables some functions by default, you need to disable this feature.

Then download the wordpress and untar:

$ wget https://wordpress.org/latest.tar.gz -O /tmp/latest.tar.gz
$ tar zxvf /tmp/latest.tar.gz

Now you have wordpress directory in your project.

Create uploads directory:

$ mkdir wordpress/wp-content/uploads

Then edit the wp-config.php file:

$ vi wordpress/wp-config.php

Of course you have to edit DB related configurations, Unique keys and Salts etc. Also don’t forget to add the following configurations:

// Use https
define('WP_HOME','https://'.$_SERVER['HTTP_HOST']);
define('WP_SITEURL','https://'.$_SERVER['HTTP_HOST']);

// Restrict admin access via https
define('FORCE_SSL_ADMIN', true);

// Get HTTPS value from the App Engine specific header.
// Otherwise you'll see infinite redirect when logging in.
$_SERVER['HTTPS'] = $_SERVER['HTTP_X_APPENGINE_HTTPS'];

Deploy

Use gcloud command to deploy:

 $ gcloud app deploy app.yaml

Then access https://YOUR-PROJECT-ID.appspot.com/ and if you see the installation screen, that’s success, horray!

One comment on “WordPress on Managed VMs (DEPRECATED)

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting this form, you accept the Mollom privacy policy.