Upgrade to PRO for Only $50/Yearโ€”Limited-Time Offer! ๐Ÿ”ฅ

WordPress as a 12 Factor App - Midwest PHP 2017

WordPress as a 12 Factor App - Midwest PHPย 2017

Love it or hate it, WordPress is here to stay. Powering over 25% of the web, it's one of the most commonly used projects out there.

WordPress strive to make life easy for their end users first and foremost, but what if I told you that with less than an hour's work you could make it a joy to work with for developers too?

By following the Twelve Factor App method (http://12factor.net/) we can deploy WordPress in a way that makes it easy to develop for, easy to update and easy to maintain. Come and watch as we take a standard WordPress install and bring it into the future.

Avatar for Michael Heap

Michael Heap

March 18, 2017
Tweet

More Decks by Michael Heap

Other Decks in Technology

Transcript

  1. @mheap 1. Codebase 2. Dependencies 3. Con๏ฌg 4. Backing Services

    5. Build, Release, Run 6. Processes 7. Port Binding 8. Concurrency 9. Disposability 10. Dev/Prod Parity 11. Logs 12. Admin Processes The Twelve-Factor App
  2. @mheap Add to version control $ git init $ git

    add . $ git commit -m "Initial Commit"
  3. @mheap commit 599d45019f92f6cc191e39014674caeeedcd87b0 Author: Scott Taylor <[email protected]> Date: Sat Aug

    27 03:49:28 2016 +0000 Bootstrap: add `composer.lock` and `src/wp-vendor` ๏ฌles. Nothing is using this code yet, just going through the motions. Ignore the ๏ฌles in `src/wp-vendor/composer` that will explode in PHP 5.2. See #36335. Built from https://develop.svn.wordpress.org/trunk@38394 git-svn-id: http://core.svn.wordpress.org/trunk@38335 1a063a9b-81f0-0310-95a4-ce76da25c4cd WordPressโ€™ composer.json :)
  4. @mheap commit f1631f4e03303945c5c47682a36c184542cf094b Author: Scott Taylor <[email protected]> Date: Wed Aug

    31 20:36:30 2016 +0000 Bootstrap: goodnight sweet prince. See #36335. Built from https://develop.svn.wordpress.org/trunk@38480 git-svn-id: http://core.svn.wordpress.org/trunk@38421 1a063a9b-81f0-0310-95a4-ce76da25c4cd WordPressโ€™ composer.json :(
  5. @mheap { "packages": { "mheap/wordpress": { "v4.7.3": { "name": "mheap/wordpress",

    "dist" : { "url" : "http://wordpress.org/wordpress-4.7.3.zip", "type": "zip" }, "source" : { "url" : "https://github.com/WordPress/WordPress", "type" : "git", "reference": "4.7.3" }, "type": "package", "version": "4.7.3" } } } }
  6. @mheap { "config": { "secure-http": false }, "repositories" : [

    { "type" : "composer", "url" : "http://example.com" } ], "require" : { "mheap/wordpress" : ">=4.7.3" } }
  7. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ””โ”€โ”€ vendor โ”œโ”€โ”€ autoload.php

    โ”œโ”€โ”€ composer โ”‚ โ”œโ”€โ”€ ClassLoader.php โ”‚ โ”œโ”€โ”€ LICENSE โ”‚ โ”œโ”€โ”€ autoload_classmap.php โ”‚ โ”œโ”€โ”€ autoload_namespaces.php โ”‚ โ”œโ”€โ”€ autoload_psr4.php โ”‚ โ”œโ”€โ”€ autoload_real.php โ”‚ โ”œโ”€โ”€ autoload_static.php โ”‚ โ””โ”€โ”€ installed.json โ””โ”€โ”€ mheap โ””โ”€โ”€ wordpress โ”œโ”€โ”€ <other ๏ฌles> โ””โ”€โ”€ wp-con๏ฌg.php
  8. @mheap { "packages": { "mheap/wordpress": { "v4.7.3": { "name": "mheap/wordpress",

    "dist" : { "url" : "http://wordpress.org/wordpress-4.7.3.zip", "type": "zip" }, "source" : { "url" : "https://github.com/WordPress/WordPress", "type" : "git", "reference": "4.7.3" }, "type": "wordpress-core", "version": "4.7.3", "require": { "johnpbloch/wordpress-core-installer": "~0.1" } } } } }
  9. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ vendor โ”‚ โ”œโ”€โ”€

    autoload.php โ”‚ โ”œโ”€โ”€ composer โ”‚ โ””โ”€โ”€ johnpbloch โ””โ”€โ”€ wordpress โ”œโ”€โ”€ <other ๏ฌles> โ””โ”€โ”€ wp-con๏ฌg.php
  10. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ vendor โ”‚ โ”œโ”€โ”€

    autoload.php โ”‚ โ”œโ”€โ”€ composer โ”‚ โ””โ”€โ”€ johnpbloch โ””โ”€โ”€ wordpress โ”œโ”€โ”€ <other ๏ฌles> โ””โ”€โ”€ wp-con๏ฌg.php
  11. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ vendor โ”œโ”€โ”€ web

    โ”‚ โ””โ”€โ”€ index.php โ”œโ”€โ”€ wordpress โ””โ”€โ”€ wp-con๏ฌg.php
  12. @mheap Edit wp-con๏ฌg.php /* That's all, stop editing! Happy blogging.

    */ /** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');
  13. @mheap Edit wp-con๏ฌg.php /* That's all, stop editing! Happy blogging.

    */ /** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/../wordpress'); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');
  14. @mheap Edit index.php define('WP_USE_THEMES', true); /** Loads the WordPress Environment

    and Template */ require( dirname( __FILE__ ) . '/wp-blog-header.php' );
  15. @mheap Edit index.php define('WP_USE_THEMES', true); /** Loads the WordPress Environment

    and Template */ require( dirname( __FILE__ ) . '/../wordpress/wp-blog- header.php' );
  16. @mheap Edit wp-con๏ฌg.php /** Absolute path to the WordPress directory.

    */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/wordpress'); define('WP_HOME', 'http://example.com'); define('CONTENT_DIR', '/wp-content'); define('WP_CONTENT_DIR', __DIR__ . '/web' . CONTENT_DIR); define('WP_CONTENT_URL', WP_HOME . CONTENT_DIR); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php');
  17. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ vendor โ”œโ”€โ”€ web

    โ”‚ โ”œโ”€โ”€ index.php โ”‚ โ””โ”€โ”€ wp-content โ”‚ โ”œโ”€โ”€ plugins โ”‚ โ”œโ”€โ”€ themes โ”‚ โ””โ”€โ”€ uploads โ”œโ”€โ”€ wordpress โ””โ”€โ”€ wp-con๏ฌg.php
  18. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ web โ”‚ โ”œโ”€โ”€

    index.php โ”‚ โ””โ”€โ”€ wp-content โ”‚ โ”œโ”€โ”€ plugins โ”‚ โ”œโ”€โ”€ themes โ”‚ โ””โ”€โ”€ uploads โ””โ”€โ”€ wp-con๏ฌg.php
  19. @mheap . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ web โ”‚ โ”œโ”€โ”€

    index.php โ”‚ โ””โ”€โ”€ wp-content โ”‚ โ”œโ”€โ”€ plugins โ”‚ โ”œโ”€โ”€ themes โ”‚ โ””โ”€โ”€ uploads โ””โ”€โ”€ wp-con๏ฌg.php
  20. @mheap { "repositories":[ { "type":"composer", "url":"https://wpackagist.org" } ], "require": {

    "johnpbloch/wordpress": ">=4.7.3", "wpackagist-plugin/captcha":">=3.9", "wpackagist-theme/hueman":">=3.3.7" } }
  21. @mheap โ”‚ โ”œโ”€โ”€ customize.php โ”‚ โ”œโ”€โ”€ edit-comments.php โ”‚ โ”œโ”€โ”€ edit-form-advanced.php

    โ”‚ โ”œโ”€โ”€ edit-form-comment.php โ”‚ โ”œโ”€โ”€ edit-link-form.php โ”‚ โ”œโ”€โ”€ edit-tag-form.php โ”‚ โ”œโ”€โ”€ edit-tags.php โ”‚ โ”œโ”€โ”€ edit.php โ”‚ โ”œโ”€โ”€ export.php โ”‚ โ”œโ”€โ”€ freedoms.php โ”‚ โ”œโ”€โ”€ images โ”‚ โ”‚ โ”œโ”€โ”€ align-center-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ align-center.png โ”‚ โ”‚ โ”œโ”€โ”€ align-left-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ align-left.png โ”‚ โ”‚ โ”œโ”€โ”€ align-none-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ align-none.png โ”‚ โ”‚ โ”œโ”€โ”€ align-right-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ align-right.png โ”‚ โ”‚ โ”œโ”€โ”€ arrows-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ arrows.png โ”‚ โ”‚ โ”œโ”€โ”€ browser-rtl.png โ”‚ โ”‚ โ”œโ”€โ”€ browser.png โ”‚ โ”‚ โ”œโ”€โ”€ bubble_bg-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ bubble_bg.gif โ”‚ โ”‚ โ”œโ”€โ”€ comment-grey-bubble-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ comment-grey-bubble.png โ”‚ โ”‚ โ”œโ”€โ”€ date-button-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ date-button.gif โ”‚ โ”‚ โ”œโ”€โ”€ generic.png โ”‚ โ”‚ โ”œโ”€โ”€ icons32-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ icons32-vs-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ icons32-vs.png โ”‚ โ”‚ โ”œโ”€โ”€ icons32.png โ”‚ โ”‚ โ”œโ”€โ”€ imgedit-icons-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ imgedit-icons.png โ”‚ โ”‚ โ”œโ”€โ”€ list-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ list.png โ”‚ โ”‚ โ”œโ”€โ”€ loading.gif โ”‚ โ”‚ โ”œโ”€โ”€ marker.png โ”‚ โ”‚ โ”œโ”€โ”€ mask.png โ”‚ โ”‚ โ”œโ”€โ”€ media-button-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ media-button-image.gif โ”‚ โ”‚ โ”œโ”€โ”€ media-button-music.gif โ”‚ โ”‚ โ”œโ”€โ”€ media-button-other.gif โ”‚ โ”‚ โ”œโ”€โ”€ media-button-video.gif โ”‚ โ”‚ โ”œโ”€โ”€ media-button.png โ”‚ โ”‚ โ”œโ”€โ”€ menu-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ menu-vs-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ menu-vs.png โ”‚ โ”‚ โ”œโ”€โ”€ menu.png โ”‚ โ”‚ โ”œโ”€โ”€ no.png โ”‚ โ”‚ โ”œโ”€โ”€ post-formats-vs.png โ”‚ โ”‚ โ”œโ”€โ”€ post-formats.png โ”‚ โ”‚ โ”œโ”€โ”€ post-formats32-vs.png โ”‚ โ”‚ โ”œโ”€โ”€ post-formats32.png โ”‚ โ”‚ โ”œโ”€โ”€ resize-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ resize-rtl-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ resize-rtl.gif โ”‚ โ”‚ โ”œโ”€โ”€ resize.gif โ”‚ โ”‚ โ”œโ”€โ”€ se.png โ”‚ โ”‚ โ”œโ”€โ”€ sort-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ sort.gif โ”‚ โ”‚ โ”œโ”€โ”€ spinner-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ spinner.gif โ”‚ โ”‚ โ”œโ”€โ”€ stars-2x.png โ”‚ โ”‚ โ”œโ”€โ”€ stars.png โ”‚ โ”‚ โ”œโ”€โ”€ w-logo-blue.png โ”‚ โ”‚ โ”œโ”€โ”€ w-logo-white.png โ”‚ โ”‚ โ”œโ”€โ”€ wheel.png โ”‚ โ”‚ โ”œโ”€โ”€ wordpress-logo-white.svg โ”‚ โ”‚ โ”œโ”€โ”€ wordpress-logo.png โ”‚ โ”‚ โ”œโ”€โ”€ wordpress-logo.svg โ”‚ โ”‚ โ”œโ”€โ”€ wpspin_light-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ wpspin_light.gif โ”‚ โ”‚ โ”œโ”€โ”€ xit-2x.gif โ”‚ โ”‚ โ”œโ”€โ”€ xit.gif โ”‚ โ”‚ โ””โ”€โ”€ yes.png โ”‚ โ”œโ”€โ”€ import.php โ”‚ โ”œโ”€โ”€ includes โ”‚ โ”‚ โ”œโ”€โ”€ admin-๏ฌlters.php โ”‚ โ”‚ โ”œโ”€โ”€ admin.php โ”‚ โ”‚ โ”œโ”€โ”€ ajax-actions.php โ”‚ โ”‚ โ”œโ”€โ”€ bookmark.php โ”‚ โ”‚ โ”œโ”€โ”€ class-automatic-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-bulk-plugin-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-bulk-theme-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-bulk-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-core-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-๏ฌle-upload-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-ftp-pure.php โ”‚ โ”‚ โ”œโ”€โ”€ class-ftp-sockets.php โ”‚ โ”‚ โ”œโ”€โ”€ class-ftp.php โ”‚ โ”‚ โ”œโ”€โ”€ class-language-pack-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-language-pack-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-pclzip.php โ”‚ โ”‚ โ”œโ”€โ”€ class-plugin-installer-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-plugin-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-plugin-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-theme-installer-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-theme-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-theme-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-walker-category-checklist.php โ”‚ โ”‚ โ”œโ”€โ”€ class-walker-nav-menu-checklist.php โ”‚ โ”‚ โ”œโ”€โ”€ class-walker-nav-menu-edit.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-ajax-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-automatic-updater.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-comments-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-๏ฌlesystem-base.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-๏ฌlesystem-direct.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-๏ฌlesystem-ftpext.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-๏ฌlesystem-ftpsockets.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-๏ฌlesystem-ssh2.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-importer.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-internal-pointers.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-links-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-list-table-compat.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-media-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-ms-sites-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-ms-themes-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-ms-users-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-plugin-install-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-plugins-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-post-comments-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-posts-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-press-this.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-screen.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-site-icon.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-terms-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-theme-install-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-themes-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-upgrader-skin.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-upgrader.php โ”‚ โ”‚ โ”œโ”€โ”€ class-wp-users-list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ comment.php โ”‚ โ”‚ โ”œโ”€โ”€ continents-cities.php โ”‚ โ”‚ โ”œโ”€โ”€ credits.php โ”‚ โ”‚ โ”œโ”€โ”€ dashboard.php โ”‚ โ”‚ โ”œโ”€โ”€ deprecated.php โ”‚ โ”‚ โ”œโ”€โ”€ edit-tag-messages.php โ”‚ โ”‚ โ”œโ”€โ”€ export.php โ”‚ โ”‚ โ”œโ”€โ”€ ๏ฌle.php โ”‚ โ”‚ โ”œโ”€โ”€ image-edit.php โ”‚ โ”‚ โ”œโ”€โ”€ image.php โ”‚ โ”‚ โ”œโ”€โ”€ import.php โ”‚ โ”‚ โ”œโ”€โ”€ list-table.php โ”‚ โ”‚ โ”œโ”€โ”€ media.php โ”‚ โ”‚ โ”œโ”€โ”€ menu.php โ”‚ โ”‚ โ”œโ”€โ”€ meta-boxes.php โ”‚ โ”‚ โ”œโ”€โ”€ misc.php โ”‚ โ”‚ โ”œโ”€โ”€ ms-admin-๏ฌlters.php โ”‚ โ”‚ โ”œโ”€โ”€ ms-deprecated.php โ”‚ โ”‚ โ”œโ”€โ”€ ms.php . โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ composer.lock โ”œโ”€โ”€ web โ”‚ โ”œโ”€โ”€ index.php โ”‚ โ””โ”€โ”€ wp-content โ””โ”€โ”€ wp-con๏ฌg.php (1762 ๏ฌles)
  22. @mheap if ($_SERVER['REMOTE_ADDR'] == '82.123.234.12') { define('DB_USER', 'prod_wp'); } else

    if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { define('DB_USER', 'root'); }
  23. @mheap if ($_SERVER['REMOTE_ADDR'] == '82.123.234.12') { include 'wp-config-staging.php'; } else

    if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { include 'wp-config-dev.php'; }
  24. @mheap composer.json { "repositories":[ { "type":"composer", "url":"https://wpackagist.org" } ], "require":

    { "johnpbloch/wordpress": ">=4.7.3", "wpackagist-plugin/captcha":">=3.9", "wpackagist-theme/hueman":">=3.3.7", "vlucas/phpdotenv": "^2.4" } }
  25. @mheap wp-con๏ฌg.php /** The name of the database for WordPress

    */ define('DB_NAME', getenv('DB_NAME')); /** MySQL database username */ define('DB_USER', getenv('DB_USER')); /** MySQL database password */ define('DB_PASSWORD', getenv('DB_PASSWORD')); /** MySQL hostname */ define('DB_HOST', getenv('DB_HOST'));
  26. @mheap wp-con๏ฌg.php /** The name of the database for WordPress

    */ define('DB_NAME', getenv('DB_NAME')); /** MySQL database username */ define('DB_USER', getenv('DB_USER')); /** MySQL database password */ define('DB_PASSWORD', getenv('DB_PASSWORD')); /** MySQL hostname */ define('DB_HOST', getenv('DB_HOST'));
  27. @mheap Release $ scp app.zip remote-host:~ $ ssh remote-host $

    unzip app.zip $ cd /var/www $ mv ~/app releases/20161201 $ ln -s releases/20161201 live_new $ mv -Tf live_new live
  28. @mheap Build $ composer install $ fpm -s dir -t

    rpm -n ${name} -v '$ {version}' .=/var/www/${name} โ€”after- install after-install.sh --after-remove after-remove.sh
  29. @mheap PHP-FPM Daemonises 12 Factor app should not write PID

    ๏ฌle Instead, rely on process manager
  30. @mheap Reducing the gap Make the time gap small Make

    the personnel gap small Make the tools gap small