Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Deploying WP Multisite to Heroku
1. Deploying WP Multisite
to Heroku
WordCamp Finland 2016
Helsinki 15.4.2016
Jussi Kinnula <jussi.kinnula@frantic.com>
https://github.com/jussikinnula
2. Prerequisites
- Mac OS X (latest)
- Note! Most of the tools are available also on Linux systems
- Homebrew:
- http://brew.sh/
- Heroku toolbelt:
- https://toolbelt.heroku.com/
- ClearDB dump (Heroku utility):
- https://github.com/josepfrantic/heroku-cleardbdump
- Bedrock (boilerplate):
- Original version (without Heroku-specific configuration): https://github.com/roots/bedrock
- Fork with Heroku & multisite related configuration: https://github.com/frc/bedrock-on-heroku
3. Installing tools, part I
After installing Homebrew & Heroku toolbelt & ClearDB dump utility, we need to
install some packages that WordPress and Heroku Local needed.
$ brew install php56 --with-fpm
$ brew install mysql redis
$ brew install php56-redis php56-timezonedb php56-igbinary
composer
$ brew install libpng jpeg giflib libtiff
…
4. Installing tools, part II
…
$ brew tap homebrew/nginx
$ brew install nginx-full --with-realip
Reverse proxy is needed for local development, we use a Node module:
$ brew install node
$ npm install -g reverse-proxy-js
6. Setup the project
$ cd ~/dev
$ git clone git@github.com:frc/bedrock-on-heroku.git my-project
$ cd my-project
$ rm -rf .git
$ git init
$ git add -A . && git commit -am ‘initial commit’
7. Set local “environment”
Make sure first that MySQL and Redis servers are running.
$ mysqladmin -uroot create my-project
$ cat > .env
CLEARDB_DATABASE_URL=mysql://root:@127.0.0.1/my-project
#WP_ALLOW_MULTISITE=true
#WP_MULTISITE_MAIN_DOMAIN=localhost.frc.io
^C
8. Composer configuration, part I
{
"name": "roots/bedrock",
"type": "project",
"license": "MIT",
"description": "A modern WordPress stack",
"homepage": "https://roots.io/bedrock/",
"authors": [
{
"name": "Scott Walkinshaw",
"email": "scott.walkinshaw@gmail.com",
"homepage": "https://github.com/swalkinshaw"
},
{
"name": "Ben Word",
"email": "ben@benword.com",
"homepage": "https://github.com/retlehs"
}
],
Please edit to your needs (project-
specific stuff generally).
10. Composer configuration, part III
"repositories": [
{
"type": "vcs",
"url": "https://github.com/frc/wp-amazon-s3-and-cloudfront"
},
{
"type": "composer",
"url": "http://wpackagist.org"
}
],
Extra repositories to get stuff
from. By default composer
installs stuff from packagist.
org repositories.
WordPress packages are
generally on wpackagist.org
and there’s on GitHub
repository + a Satis custom
repository for extra packages.
11. Composer configuration, part IV
"require-dev": {
"heroku/heroku-buildpack-php": "dev-master"
},
Heroku Local development tools are installed by
simply having a development require for Heroku’
s PHP buildpack.
12. Composer configuration, part V
"require": {
"ext-redis": "*",
"ext-gd": "*",
"frc/batcache": "~1.2-p1",
"deliciousbrains/wp-amazon-s3-and-cloudfront": "dev-frc",
"wpackagist-plugin/amazon-web-services": "~0.3.2",
"wpackagist-plugin/sendgrid-email-delivery-simplified": "~1.
6.2",
"wpackagist-plugin/limit-login-attempts": "~1.7.1",
"tillkruss/redis-object-cache": "~1.2.1",
"frc/wp-env-heroku-cleardb": "~1.0.1",
"frc/wp-env-heroku-redis": "~1.0.0",
"frc/wp-env-heroku-sendgrid": "~1.0.0",
"frc/wp-env-heroku-amazon-aws": "~1.0.0",
"php": "^5.6",
"composer/installers": "~1.0.21",
"vlucas/phpdotenv": "~2.0.1",
"johnpbloch/wordpress": "~4.3.1"
},
Requirements include some extra
packages related to caching (page
cache batcache, object cache redis-
object-cache), Amazon integration
(media files to S3 bucket), Sendgrid
integration (send E-mails via Sendgrid)
and Advanced Custom Fields Pro.
Heroku configuration is read with wp-
env-heroku-???????? Modules
(ClearDB, Redis, SendGrid and Amazon
AWS credentials).
13. Composer configuration, part VI
"scripts": {
"post-update-cmd": [
"cp web/app/plugins/wordpress-mu-domain-mapping/sunrise.php
web/app/sunrise.php",
"cp web/app/plugins/redis-object-cache/includes/object-cache.
php web/app/object-cache.php",
"cp web/app/mu-plugins/batcache/advanced-cache.php
web/app/advanced-cache.php"
],
"post-install-cmd": [
"cp web/app/plugins/wordpress-mu-domain-mapping/sunrise.php
web/app/sunrise.php",
"cp web/app/plugins/redis-object-cache/includes/object-cache.
php web/app/object-cache.php",
"cp web/app/mu-plugins/batcache/advanced-cache.php
web/app/advanced-cache.php"
]
},
Post update commands are run to
copy sunrise.php, object-cache.php
and advanced-cache.php to their
correct places. Post install does
similar stuff.
Sunrise is for custom domain names
plug-in, and the other two are for
caching.
14. Composer configuration, part VII
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-
muplugin"],
"web/app/plugins/{$name}/": ["type:wordpress-plugin"],
"web/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "web/wp"
}
}
Defining installer paths and WordPress
installation directory.
Note that this “web” and “web/wp” style of
directories comes from the Bedrock
structures.
16. # Get reverse proxy running
$ sudo reverse-proxy
--port 80 --target 5000
$ heroku local
http://localhost.frc.io
17. WordPress setup (common)
● We’ll do first a regular WordPress setup, no multi-site related stuff
● After everything is setup, then heroku local will be stopped (CTRL+C) - and
.env modified to the following:
CLEARDB_DATABASE_URL=mysql://root:@127.0.0.1/my-project
WP_ALLOW_MULTISITE=true
#WP_MULTISITE=localhost.frc.io
● Then just restart heroku local …
18. WordPress setup (enable multisite)
● Now with WP_ALLOW_MULTISITE=true
being active, you can get to enabling
multisite on WP admin
● You don’t have to actually do any
copy&pasting for the code after
enabling multisite, as we have the
necessary code already implemented
in config/application.php -file
● After enabling multisite, just stop
heroku local (CTRL+C) and
uncomment the last line in .env and
start it again
● Setting the multisite domain sets also
the other definitions
CLEARDB_DATABASE_URL=mysql://root:@127.0.0.1
/my-project
WP_ALLOW_MULTISITE=true
WP_MULTISITE_MAIN_DOMAIN=localhost.frc.io
if (getenv('WP_MULTISITE_MAIN_DOMAIN')) {
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', getenv
('WP_MULTISITE_MAIN_DOMAIN'));
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('SUNRISE', true);
}