Do you want to do development on multiple sites with different setups concurrently, but do not have to update core in each install every time a new version is released? Are you developing for a single site environment, but don not want to spin up a new development server for every site so you do not have to worry about multisite quirks?
If you answered yes to either of these questions, a multi-tenant WordPress install is just what you need!
Come learn how I adapted Cliff Seal's talk from WPCampus 2016 into a simple VVV site that allows you to develop for as many sites as you want while still maintaining the flexibility of having a separate directory structure and separate databases (not just tables) and still only have to update plugins/themes/core once for all of your sites.
3. • WordPress dev at WashU since December 2011
• “Professional code monkey, amateur grease monkey.”
• WordCamp STL organizer
• Luckiest WordPress dev in the world!
About Me
4. December 2011
• 0 WordPress sites
• 1,000s of SharePoint sites
(OK, maybe an exaggeration but who cares about SP)
• 3 Devs
July 2013
• 100s of WordPress Sites hosted locally
• 100s of WordPress Sites hosted on CampusPress
• 0 SharePoint sites
(OK, maybe an exaggeration but who cares about SP)
• >25 Devs, designers, content strategists, project managers, etc…
WordPress@WashU
5. In the beginning…we coded every site like it was the only site we
were doing, which meant:
• Blank Slate: we didn’t even use Bootstrap
• No Plugins: wrote all functionality
into the theme
• No Version control: ¯_(ツ)_/¯
• No Access: WP Easy Uploader FTW (?)
WordPress@WashU
6. Since then, we’ve gotten smarter:
• Unified theme: one theme for CP, Med School, and Main Campus
• SO Many plugins: 34 on medicine
(but only 17 on wustl.edu)
• SO Much version control: GitHub,
Bitbucket, BitBucket server
• No Access: Still no SFTP/SSH access,
but that’s OK
WordPress@WashU
7. While we may have a unified theme, there are still “one off”s that
we handle, plus child themes and legacy sites.
We have over 30 “in-house” plugins that are used on at least one
site.
Multiply X by Y and you just get a headache
Developing for WordPress@WashU
8. First attempt – let’s not talk about that
Second attempt – Symlinks to Symlinks in Symlinks (OK, maybe not THAT bad)
Third (and so far final) attempt – Multitennant!!!
Developing for WordPress@WashU
9. WPCampus 2016
Sarasota, FL
…my parent’s just moved to Bradenton…
…I can crash on their couch…
…If I only need to get the cost of the ticket approved…
…HOLY COW, I’M IN FLORIDA!!!
…but first a story
10. “ ‘..a software architecture in which a single instance of software
runs on a server and serves multiple tenants…’
-the Internet”
-Mike Corkum
Multitenant 101
11. Multitenant ≠ Multisite
• Per site wp-config file
• Multiple Databases vs
Single Database
• One set of core files,
independent uploads
(or entire wp-content folder)
Multitenant 101
12. N.B. I came up with the term “landlord” to describe the main set of
WordPress Core files
Multitenant 101
13. • April 2014 - WordPress 3.9 introduced symlinking for plugins
which was the final component needed for general use
• There were articles and “hacks” to do it before, but don’t be this
guy:
Multitenant 201
Or this
guy
14. Multitenant 201
WP Core files Database #2Database #1
Site #3Site #3Site #3
Symlink
wp-config DB
settings
16. Using VVV – create vvv-custom.yml and copy-and-paste this:
sites:
<your_site_name_here>:
repo: https://github.com/coderaaron/mtv-vvv-site.git
hosts:
- <your_site_domain_here>.dev
Multitenant How-to
17. But only one site isn’t that much fun, try this:
sites:
<site1_name_here>:
repo: https://github.com/coderaaron/mtv-vvv-site.git
hosts:
- <site1_domain_here>.dev
<site2_name_here>:
repo: https://github.com/coderaaron/mtv-vvv-site.git
hosts:
- <site2_domain_here>.dev
Multitenant How-to
20. • Checked to see if there is a landlord
– If not download WordPress Core
– Create a certificate to sign other certificates
• Create database
• Setup symlinks for mu-plugins, plugins, and themes
• Create a certificate and signs it using the landlord’s certificate
• Copies the modified wp-config.php and index.php
• Runs famous “5 Minute Install”
…but what’d that do?
21. That’s great but I use…
• Local
• DesktopServer
• Lando
• Docker
• Virtual machines
• Good ol’ fashion server
Multitenant How-to
23. • Install WordPress (no need to do 5 minute install, just need core
files)
– Change wp-config.php to
require$_SERVER['DOCUMENT_ROOT'].'/wp-config.php’;
Manual Multitenant how-to
24. • If you want to use WP-CLI add this to wp-config.php:
//require_once(ABSPATH. 'wp-settings.php’);
if( '<PATH_TO_LANDLORD>’ == $_SERVER['DOCUMENT_ROOT']) {
$_SERVER['DOCUMENT_ROOT']= getcwd();
}
• Replace <PATH_TO_LANDLORD> with the absolute path to you core files
(i.e. /var/www/wp_core)
Manual Multitenant how-to
25. • Create a folder (that your server can access) for your uploads
• Inside folder you just created
– Create wp-content folder and uploads
– Create a symlink to folder containing core files (named wp)
Manual Multitenant how-to
27. • Set up wp-config.php as normal (salts, wp_debug, etc)
– Add to wp-config.php:
define( 'WP_HOME', 'https://<YOUR_URL_HERE>’);
define( 'WP_SITEURL','https://<YOUR_URL_HERE>/wp’ );
define( 'WP_CONTENT_DIR',dirname( __FILE__ ) . '/wp-content’);
define( 'WP_CONTENT_URL','https://<YOUR_URL_HERE>/wp-content');
Manual Multitenant how-to
28. • If you want to use independent themes or plugins folder, create
them here
• If you want to use a unified themes or plugins folder, create
symlinks to their locations
Manual Multitenant how-to