Skip to content

Instantly share code, notes, and snippets.

@arkadijs
Last active January 9, 2021 14:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadijs/9b0f3e17e08471ed4c5f to your computer and use it in GitHub Desktop.
Save arkadijs/9b0f3e17e08471ed4c5f to your computer and use it in GitHub Desktop.
Workshop: Deploying WordPress on Google App Engine :: PHP and Cloud SQL http://ldn.lv/events/166755872 http://goo.gl/F5K4Qn

Google Cloud SDK

There are two alternatives to start with the SDK:

  1. install SDK locally;
  2. use provided Linux VM in the cloud via ssh.

Note: everyone will get a separate index, ie. hacker02, hacker03, etc.

$ ssh hacker01@wp-workshop.hosting.lv

Google Cloud Platform :: App Engine project

Use your Google account to sign-in into Google Cloud Developers Console and create a new project. Choose nice and unique Project ID.

Until billing is enabled you won't be able to create Cloud SQL instances - that's a paid feature with no free tier. Instead we'll be using a MySQL instance from another Google Cloud project that has billing in-place.

Now, you must tell me the Project ID so I could add an access to Cloud SQL MySQL instance and Cloud Storage bucket, which is also a paid feature.

In case you're setting up the billing and creating your own Cloud SQL instance, it must be created in United States Region. Also, create Cloud Storage bucket for media files and add your-project-id@appspot.gserviceaccount.com as bucket Writer.

WordPress install

Download and unpack WordPress:

$ mkdir wp-workshop
$ cd wp-workshop
$ curl http://wordpress.org/latest.tar.gz | tar xz
$ ls -ld wordpress

Download wp-config and App Engine manifests:

$ wget -P wordpress/ \
    https://gist.githubusercontent.com/arkadijs/9b0f3e17e08471ed4c5f/raw/wp-config.php
$ wget \
    https://gist.githubusercontent.com/arkadijs/9b0f3e17e08471ed4c5f/raw/app.yaml \
    https://gist.githubusercontent.com/arkadijs/9b0f3e17e08471ed4c5f/raw/cron.yaml \
    https://gist.githubusercontent.com/arkadijs/9b0f3e17e08471ed4c5f/raw/php.ini

Now, edit wordpress/wp-config.php, replacing index in DB_NAME with the index you've got for hacker01 ssh login. Also edit app.yaml, replacing application: your-project-id to match the Project ID (not the name) that is assigned to your Google Cloud Platform project.

Download necessary plug-ins, first Google App Engine for WordPress:

$ wget -O appengine-wordpress-plugin.zip \
    https://github.com/GoogleCloudPlatform/appengine-wordpress-plugin/archive/master.zip
$ unzip appengine-wordpress-plugin.zip -d wordpress/wp-content/plugins/
$ rm appengine-wordpress-plugin.zip

then Batcache and Memcached Object Cache:

$ wget -P wordpress/wp-content/ \
    https://raw.githubusercontent.com/jeremyfelt/Memcached-Object-Cache/master/object-cache.php \
    https://raw.githubusercontent.com/Automattic/batcache/master/advanced-cache.php
$ wget -P wordpress/wp-content/plugins/ \
    https://raw.githubusercontent.com/Automattic/batcache/master/batcache.php

Ready to deploy in wp-workshop directory:

wp-workshop $ appcfg.py -e your-account@gmail.com \
    --oauth2 --noauth_local_webserver update .

Note trailing dot.

MySQL setup

Create schema in provided Cloud SQL instance:

$ mysql -h wp-workshop-db.hosting.lv -u root -pwp-workshop-password
mysql> create database wordpress_db01 default character set utf8;
Query OK, 1 row affected (0.26 sec)

Use your own 02, 03, etc. index!

WordPress setup

Open https://your-project-id.appspot.com/wp-admin/install.php in browser. Fill-in the form, press the button, wait a little bit.

Login and choose Plugins in menu on the left. Enable Batcache Manager and Google App Engine for WordPress plug-ins.

Go to GAE plug-in settings and enter wp-workshop-bucket into Upload Settings / Bucket Name, then save changes.

That's it!

application: your-project-id
version: 1
runtime: php
api_version: 1
handlers:
- url: /(.*\.(htm|html|css|js))$
static_files: wordpress/\1
upload: wordpress/.*\.(htm|html|css|js)$
application_readable: true
- url: /wp-content/(.*\.(ico|jpg|png|gif))$
static_files: wordpress/wp-content/\1
upload: wordpress/wp-content/.*\.(ico|jpg|png|gif)$
application_readable: true
- url: /(.*\.(ico|jpg|png|gif))$
static_files: wordpress/\1
upload: wordpress/.*\.(ico|jpg|png|gif)$
- url: /wp-admin/(.+)
script: wordpress/wp-admin/\1
secure: always
- url: /wp-admin/
script: wordpress/wp-admin/index.php
secure: always
- url: /wp-login.php
script: wordpress/wp-login.php
secure: always
- url: /wp-cron.php
script: wordpress/wp-cron.php
login: admin
- url: /xmlrpc.php
script: wordpress/xmlrpc.php
- url: /wp-(.+).php
script: wordpress/wp-\1.php
- url: /(.+)?/?
script: wordpress/index.php
cron:
- description: wordpress cron tasks
url: /wp-cron.php
schedule: every 2 hours
google_app_engine.enable_functions = php_sapi_name,gc_enabled
allow_url_include = On
upload_max_filesize = 8M
<?php
define('WP_CACHE', true);
define('DB_NAME', 'wordpress_db01'); // use index of your hacker01 account!
define('DB_HOST', ':/cloudsql/acn-poc-multicloud:wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443)
$protocol_to_use = 'https://';
else
$protocol_to_use = 'http://';
define('WP_SITEURL', $protocol_to_use . $_SERVER['HTTP_HOST']);
define('WP_HOME', $protocol_to_use . $_SERVER['HTTP_HOST']);
define('AUTH_KEY', 'maiDooJae0');
define('SECURE_AUTH_KEY', 'ooTh6aiphe');
define('LOGGED_IN_KEY', 'reoP6Fiuxa');
define('NONCE_KEY', 'aiGi5xeiNe');
define('AUTH_SALT', 'ar5aPhohga');
define('SECURE_AUTH_SALT', 'mie6ahk2Ju');
define('LOGGED_IN_SALT', 'leeHuaX5iF');
define('NONCE_SALT', 'ohwaa9Toob');
$table_prefix = 'wp_';
define('WPLANG', '');
define('WP_DEBUG', false);
if (!defined('ABSPATH'))
define('ABSPATH', dirname(__FILE__) . '/wordpress/');
require_once(ABSPATH . 'wp-settings.php');
$batcache = [
'seconds'=>0,
'max_age'=>30*60, // 30 minutes
'debug'=>false
];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment