Deploying WP Multisite to Heroku
-
Upload
jussi-kinnula -
Category
Internet
-
view
448 -
download
2
Transcript of Deploying WP Multisite to Heroku
Deploying WP Multisiteto Heroku
WordCamp Finland 2016Helsinki 15.4.2016
Jussi Kinnula <[email protected]>https://github.com/jussikinnula
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
Installing tools, part IAfter 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
…
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
Please test, that everything works…
Setup the project$ cd ~/dev
$ git clone [email protected]:frc/bedrock-on-heroku.git my-project
$ cd my-project
$ rm -rf .git
$ git init
$ git add -A . && git commit -am ‘initial commit’
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
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": "[email protected]",
"homepage": "https://github.com/swalkinshaw"
},
{
"name": "Ben Word",
"email": "[email protected]",
"homepage": "https://github.com/retlehs"
}
],
Please edit to your needs (project-specific stuff generally).
Composer configuration, part II "keywords": [
"bedrock", "roots", "wordpress", "stack",
"composer", "vagrant", "wp"
],
"support": {
"issues": "https://github.
com/roots/bedrock/issues",
"forum": "https://discourse.roots.
io/category/bedrock"
},
"config": {
"preferred-install": "dist"
},
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.
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.
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).
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.
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.
$ composer install
# Get reverse proxy running$ sudo reverse-proxy \ --port 80 --target 5000
$ heroku local
http://localhost.frc.io
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 …
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);
}
Main site:http://localhost.frc.io
Site #1:http://anything.localhost.frc.io
Site #2:http://else.localhost.frc.io
Deploy to Heroku$ heroku create --region eu my-project
$ heroku addons:create cleardb:ignite
$ heroku addons:create heroku-redis:hobby-dev
$ git push heroku master
$ heroku cleardb:push my-project --search localhost.frc.io \
--replace wordcamp.frc.io
$ heroku domains:add wordcamp.frc.io
$ heroku domains:add *.wordcamp.frc.io
http://wordcamp.frc.io
http://anything.wordcamp.frc.io
http://else.wordcamp.frc.io
http://wordcamp.aksurules.com
Thanks