wordpress for the modern php developer

238
@tweetingsherry #phpuk17 ~ ChrisSherry $ WordPress for the modern PHP developer

Upload: chris-sherry

Post on 21-Feb-2017

136 views

Category:

Software


1 download

TRANSCRIPT

Page 1: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ ChrisSherry $ WordPress for the modern PHP developer

Page 2: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ ChrisSherry $ WordPress for the modern PHP developer

Page 3: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ ChrisSherry $ WordPress for the modern PHP developer

Page 4: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 5: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 6: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 7: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 8: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 9: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 10: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 11: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 12: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Version Control

Page 13: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

See who changed what, when

Page 14: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

See who changed what, whenMultiple people working on the same files simultaneously

Page 15: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

See who changed what, whenMultiple people working on the same files simultaneouslyWork on features in parallel

Page 16: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

See who changed what, whenMultiple people working on the same files simultaneouslyWork on features in parallelRoll back to previous versions

Page 17: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

See who changed what, whenMultiple people working on the same files simultaneouslyWork on features in parallelRoll back to previous versionsGo home on time

Page 18: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

ALL THE THINGS

~/site $ git init ~/site $ git add —-all

Page 19: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-config.php wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 20: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-config.php wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 21: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 22: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Our users can change our codebase using the editor tool

Page 23: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

... define('DISALLOW_FILE_EDIT', true);

/wp-config.php

Page 24: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

... define('DISALLOW_FILE_EDIT', true);

/wp-config.php

define('AUTOMATIC_UPDATER_DISABLED', true);

Page 25: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-config.php wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 26: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-config.php wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 27: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-config.php wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 28: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php

wp-config.php

readme.htmllicense.txt wp-activate.php wp-admin wp-blog-header.php

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php wp-includes wp-links-opml.php

wp-load.php wp-login.php wp-mail.php wp-settings.php wp-signup.php wp-trackback.php xmlrpc.php

Page 29: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 30: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 31: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 32: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 33: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 34: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

if (!defined('ABSPATH')) { define(

'ABSPATH', dirname(__FILE__) . '/'

);}

/wp-config.php...

Page 35: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

if (!defined('ABSPATH')) { define(

'ABSPATH', dirname(__FILE__) . '/wordpress/'

); }

/wp-config.php...

Page 36: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

option_value https://site.com https://site.com WordPress Just another WordPress site ...

option_name siteurl

home blogname

blogdescription ...

wp_options

Page 37: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

option_value https://site.com https://site.com WordPress Just another WordPress site ...

/wordpressoption_name

siteurl home

blogname blogdescription

...

wp_options

Page 38: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

Page 39: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php wp-includes wp-links-opml.php wp-load.php wp-login.php

Page 40: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php

index.php

wp-includes

plugins themes

wp-links-opml.php wp-load.php wp-login.php

Page 41: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php

index.php

wp-includes

plugins themes

wp-links-opml.php wp-load.php wp-login.php

index.php hello.php

Page 42: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php

index.php

wp-includes

plugins themes

wp-links-opml.php wp-load.php wp-login.php

index.php twentyeleven twentytwelve twentythirteen twentyfourteen twentyfifiteen twentysixteen

Page 43: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress

wp-comments- post.php

wp-config- sample.php

wp-content wp-cron.php

index.php

wp-includes

plugins themes

wp-links-opml.php wp-load.php wp-login.php

wp-content

index.php twentyeleven twentytwelve twentythirteen twentyfourteen twentyfifiteen twentysixteen

Page 44: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

plugins themes

Page 45: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

plugins themes

advanced-custom-fields debug-bar awesome-plugin

Page 46: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content' ); define( 'WP_CONTENT_URL', '/wp-content' );

/wp-config.php...

Page 47: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

Page 48: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

core code

Page 49: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

core code application code

Page 50: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

YOU MADE A NEW FOLDER

I’M GLAD I CHOSE THIS TRACK

Page 51: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

GENE WILDER 1933-2016

Page 52: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

Page 53: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content.gitignore

Page 54: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/.DS_Store

/wordpress

/.gitignore

Page 55: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ $ git clone https://github.com/chrissherry/site

Page 56: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ $ git clone https://github.com/chrissherry/site

.git index.php wp-config.php wp-content.gitignore

Page 57: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ $ git clone https://github.com/chrissherry/site

.git index.php wp-config.php wp-content.gitignore

Page 58: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Dependency Management

Page 59: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 60: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

&

Page 61: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 62: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 63: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/johnpbloch/wordpress

Page 64: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/johnpbloch/wordpress

Page 65: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 66: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Default

type:library

/vendor/[vendor]/[name]

Page 67: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Default

type:library

/vendor/[vendor]/[name]

Custom

type: wordpress-core

/wordpress

Page 68: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ composer require johnpbloch/wordpress

~/site $ composer init

~/site $ composer install

Page 69: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ composer require johnpbloch/wordpress

{ "require": { "johnpbloch/wordpress": "^4.5"}

}

/composer.json

~/site $ composer init

~/site $ composer install

Page 70: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-contentcomposer.json composer.lock.gitignore

Page 71: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-contentcomposer.json composer.lock.gitignore

Page 72: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-contentcomposer.json composer.lock.gitignore

Page 73: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-contentcomposer.json composer.lock.gitignore

Page 74: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-contentcomposer.json composer.lock.gitignore

Page 75: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced-custom-fields

composer.json composer.lock.gitignore

debug-bar awesome-plugin

Page 76: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

wpackagist.org

Page 77: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

wpackagist.org

type: wordpress-plugin /wp-content/plugins type: wordpress-theme /wp-content/themes

Custom

Page 78: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

.git index.php wp-config.phpwordpress wp-content

plugins themes

Page 79: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/composer/installers

Page 80: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { "johnpbloch/wordpress": "^4.5", "wpackagist-plugin/advanced-custom-fields": "~4.4"}

}

/composer.json

Page 81: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

https://wordpress.org/plugins/advanced-custom-fields

Page 82: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

https://wordpress.org/plugins/advanced-custom-fields

Page 83: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

https://wordpress.org/plugins/advanced-custom-fields

Page 84: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

https://wordpress.org/plugins/advanced-custom-fields

Page 85: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { "johnpbloch/wordpress": "^4.5", "wpackagist-plugin/advanced-custom-fields": "4.4"}

}

/composer.json

Page 86: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { "johnpbloch/wordpress": "^4.5", "wpackagist-plugin/advanced-custom-fields": "4.4"}

}

/composer.json

Page 87: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/composer.json{ "require": { "johnpbloch/wordpress": "^4.5", "wpackagist-plugin/advanced-custom-fields": "4.4"}, "repositories": [ { "type": "composer", "url": "https://wpackagist.org" } ]

}

Page 88: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { "johnpbloch/wordpress": "^4.5", "wpackagist-plugin/advanced-custom-fields": "4.4"}, "require-dev": { "wpackagist-plugin/debug-bar": "*"}, "repositories":[...]

}

/composer.json

~/site $ composer require —-dev wpackagist-plugin/debug-bar

Page 89: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced- custom-fields

composer.json composer.lock.gitignore

awesome-plugindebug-bar

Page 90: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced- custom-fields

composer.json composer.lock.gitignore

awesome-plugindebug-bar

Page 91: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/* !/wp-content/plugins/.gitkeep

/.gitignore

Page 92: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced- custom-fields

composer.json composer.lock.gitignore

awesome-plugindebug-bar

Page 93: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced- custom-fields

composer.json composer.lock.gitignore

awesome-plugindebug-bar

Page 94: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/*!/wp-content/plugins/.gitkeep !/wp-content/plugins/awesome-plugin

/.gitignore

Page 95: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 96: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin

Page 97: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin

Page 98: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

chrissherry/awesome-plugin v1.0

v2.0

TAGS v1.0 (awesome)v2.0 (more awesome!) Site B

Site AGithub

Page 99: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin

Page 100: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin

Page 101: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin/composer.json

Page 102: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin/composer.json

Page 103: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/chrissherry/awesome-plugin/composer.json

Page 104: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { {...}, "chrissherry/awesome-plugin": "~1.0" }

/composer.json

Page 105: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { {...}, "chrissherry/awesome-plugin": "~1.0" } , "repositories": [ {...},

{ "type": "vcs", "url": "https://github.com/chrissherry/awesome-p..." }

] }

/composer.json

Page 106: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

advanced-custom-fields

composer.json composer.lock.gitignore

awesome-plugindebug-bar

Page 107: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

composer.json composer.lock.gitignore

awesome-theme

Page 108: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.phpwordpress wp-content

plugins themes

composer.json composer.lock.gitignore

awesome-theme storefront sydney twentysixteen

Page 109: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/* !/wp-content/plugins/.gitkeep

/.gitignore

Page 110: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/* !/wp-content/plugins/.gitkeep

/.gitignore

/wp-content/themes/* !/wp-content/themes/.gitkeep

Page 111: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/* !/wp-content/plugins/.gitkeep

/.gitignore

/wp-content/themes/* !/wp-content/themes/.gitkeep!/wp-content/themes/awesome-theme

Page 112: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress/wp-content/plugins/* !/wp-content/plugins/.gitkeep

/.gitignore

Page 113: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

ONE DOES NOT SIMPLY

CLICK TO UPDATE THINGS

Page 114: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

wordpress.org/plugins/members

Page 115: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { ..., "wpackagist-plugin/members": "1.1.3" },

"repositories":[...] }

/composer.json

~/site $ composer require wpackagist-plugin/members

Page 116: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Defined versions for dependancies

Page 117: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Defined versions for dependanciesLess third party code in the repository

Page 118: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Defined versions for dependanciesLess third party code in the repositoryGreater reliance on 3rd party availability

Page 119: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Uploads

Page 120: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Uploads

Page 121: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/wordpress

/wp-content/uploads/* /wp-content/plugins/*!/wp-content/plugins/.gitkeep

...

/.gitignore

Page 122: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

s3tools.org/s3cmd

Page 123: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/humanmade/s3-uploads

Page 124: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ composer require hadyfayed/s3-uploads

{ "require": { ..., "hadyfayed/s3-uploads": "2.0" },

"repositories":[...] }

/composer.json

Page 125: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ rsync -avz [email protected]:/var/www/mysite/wp-content/uploads wp-content/uploads

Page 126: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Smaller repository -don’t need version control over uploads

Page 127: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Smaller repository -don’t need version control over uploadsFaster clone and deploy times

Page 128: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Smaller repository -don’t need version control over uploadsFaster clone and deploy timesRemote backups of our uploads

Page 129: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Databases

Page 130: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

prod:~/site $ mysqldump -u user -p dbname > db.sql

~/site $ scp [email protected]:site/db.sql db.sql

~/site $ mysql -u user -p dbname < db.sql

Page 131: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Environments

Page 132: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

option_name siteurl

home blogname

blogdescription ...

option_value https://site.com/wordpress https://site.com WordPress Just another WordPress site ...

wp_options

Page 133: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

option_name siteurl

home blogname

blogdescription ...

option_value https://staging.site.com/wordpre… https://staging.site.com WordPress Just another WordPress site ...

wp_options

Page 134: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

...

...

define('WP_HOME', 'https://site.com'); define('WP_SITEURL', 'https://site.com/wordpress');

/wp-config.php

Page 135: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

//define('WP_HOME', 'https://site.com'); //define('WP_SITEURL', 'https://site.com/wordpress… define('WP_HOME', 'https://staging.site.com'); define('WP_SITEURL', 'https://staging.site.com/wor…

/wp-config.php...

...

Page 136: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

server { listen 443; server_name staging.site.com; env WP_ENV=staging ...

/etc/nginx/sites-enabled/vhost.conf

Page 137: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

server { listen 443; server_name staging.site.com; env WP_ENV=staging ...

switch ($_ENV['WP_ENV']) { case 'staging': define('WP_HOME', 'https://staging.site.com… define('WP_SITEURL', 'https://staging.site.… ...

/wp-config.php

/etc/nginx/sites-enabled/vhost.conf

Page 138: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

server { listen 443; server_name staging.site.com; env WP_ENV=staging ...

switch ($_ENV['WP_ENV']) { case 'staging': define('WP_HOME', 'https://staging.site.com… define('WP_SITEURL', 'https://staging.site.… ...

/wp-config.php

/etc/nginx/sites-enabled/vhost.conf

define('WP_HOME', 'https://staging.site.com… define('WP_SITEURL', 'https://staging.site.…

Page 139: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

define('DB_NAME', 'database_name_here');define('DB_USER', 'username_here');define('DB_PASSWORD', 'password_here');define('DB_HOST', 'localhost'); define('WP_HOME', 'https://site.com'); define('WP_SITEURL', 'https://site.com/wordp… define('AUTH_KEY', 'put your unique phrase…define('SECURE_AUTH_KEY', 'put your unique phrase…define('LOGGED_IN_KEY', 'put your unique phrase… define('WP_DEBUG', true);

... /wp-config.php

...

Page 140: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

define('DB_NAME', 'database_name_here');define('DB_USER', 'username_here');define('DB_PASSWORD', 'password_here');define('DB_HOST', 'localhost'); define('WP_HOME', 'https://site.com'); define('WP_SITEURL', 'https://site.com/wordp… define('AUTH_KEY', 'put your unique phrase…define('SECURE_AUTH_KEY', 'put your unique phrase…define('LOGGED_IN_KEY', 'put your unique phrase… define('WP_DEBUG', true); ...

... /wp-config.php

Page 141: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

define('DB_NAME', 'database_name_here');define('DB_USER', 'username_here');define('DB_PASSWORD', 'password_here');define('DB_HOST', 'localhost'); define('WP_HOME', 'https://site.com'); define('WP_SITEURL', 'https://site.com/wordp… define('AUTH_KEY', 'put your unique phrase…define('SECURE_AUTH_KEY', 'put your unique phrase…define('LOGGED_IN_KEY', 'put your unique phrase…define('WP_DEBUG', true); ...

... /wp-config.php

Page 142: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

KEEP IT SAFE

KEEP IT SECRET

Page 143: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 144: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 145: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

github.com/vlucas/phpdotenv

Page 146: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

{ "require": { {...} "vlucas/phpdotenv": "^1.0" }, ...

}

/composer.json

~/site $ composer require vlucas/phpdotenv

Page 147: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

vendor

Page 148: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

vendor

Page 149: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

vendor

Page 150: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

DB_NAME=dbnameDB_USER=userDB_PASSWORD=correcthorsebatterystapleDB_HOST=localhost WP_ENV=developmentWP_HOME=https://site.comWP_SITEURL=https://site.com/wordpress

/.env

Page 151: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

DB_NAME=dbnameDB_USER=userDB_PASSWORD=correcthorsebatterystapleDB_HOST=localhost WP_ENV=developmentWP_HOME=https://site.comWP_SITEURL=https://site.com/wordpress

/.env

Page 152: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Page 153: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Dotenv::load('.env');

Page 154: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Dotenv::load('.env'); define('DB_NAME', $_SERVER['DB_NAME']));define('DB_USER', $_ENV['DB_USER']); define('DB_PASSWORD', getenv('DB_PASSWORD'));define('DB_HOST', getenv('DB_HOST'));

define('WP_HOME', getenv('WP_HOME')); define('WP_SITEURL', getenv('WP_SITE_URL’)); ...

Page 155: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Dotenv::load('.env'); define('DB_NAME', $_SERVER['DB_NAME']));define('DB_USER', $_ENV['DB_USER']); define('DB_PASSWORD', getenv('DB_PASSWORD'));define('DB_HOST', getenv('DB_HOST'));

define('WP_HOME', getenv('WP_HOME')); define('WP_SITEURL', getenv('WP_SITE_URL’)); ...

Page 156: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Dotenv::load('.env');

define('DB_NAME', $_SERVER['DB_NAME']));define('DB_USER', $_ENV['DB_USER']);define('DB_PASSWORD', getenv('DB_PASSWORD'));define('DB_HOST', getenv('DB_HOST')); ...

Page 157: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php /wp-config.php

Dotenv::load('.env');Dotenv::required(['DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL']);

define('DB_NAME', $_SERVER['DB_NAME']));define('DB_USER', $_ENV['DB_USER']);define('DB_PASSWORD', getenv('DB_PASSWORD'));define('DB_HOST', getenv('DB_HOST')); ...

Page 158: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/.env

/wordpress

/wp-content/uploads/* ...

/.gitignore

Page 159: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Easy to locate and update

Page 160: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Easy to locate and updatePer environment configuration

Page 161: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Easy to locate and updatePer environment configurationNot in source control

Page 162: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Easy to locate and updatePer environment configurationNot in source controlReady for open source

Page 163: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Easy to locate and updatePer environment configurationNot in source controlReady for open sourceEasy to store outside of webroot

Page 164: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

vendor

Page 165: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

server { ... root /var/www/site ...

/etc/nginx/sites-enabled/vhost.conf

vendor

Page 166: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php

wp-config.php

wordpress

wp-content

composer.json composer.lock.gitignore.git.env

web

server { ... root /var/www/site ...

/etc/nginx/sites-enabled/vhost.conf

/web

vendor

Page 167: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

composer.json composer.lock.gitignore.git.env web

server { ... root /var/www/site ...

/etc/nginx/sites-enabled/vhost.conf

/web

vendor

Page 168: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php wordpress wp-content

composer.json composer.lock.gitignore.git.env web vendor

Page 169: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version control

Page 170: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version controlDependencies managed

Page 171: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version controlDependencies managedBackups of uploads & databases

Page 172: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version controlDependencies managedBackups of uploads & databasesIsolated configuration for environments

Page 173: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version controlDependencies managedBackups of uploads & databasesIsolated configuration for environments

Page 174: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 175: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 176: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

roots.io/bedrock

Page 177: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

I DONT ALWAYS USE BEDROCK

Page 178: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Only keeping what we need in version control Dependencies managed Backups of uploads & databases Isolated configuration for environmentsActive open source community

Page 179: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php wordpress wp-content

composer.json composer.lock.gitignore.git.env web vendor

Page 180: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php wordpress wp-content

composer.json composer.lock.gitignore.git.env web vendor

Page 181: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php wp app

composer.json composer.lock.gitignore.git.env web vendor

Page 182: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/composer.json

Page 183: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

/composer.json{ ..., "extra": { "installer-paths": { "web/app/plugins/{$name}/": ["type:wordpress-plugin"], "web/app/themes/{$name}/": ["type:wordpress-theme"] }, "wordpress-install-dir": "wp" } } }

Page 184: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php

composer.json composer.lock.gitignore.git.env web vendor

wp app

Page 185: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

index.php wp-config.php

composer.json composer.lock.gitignore.git.env web vendor

wp-contentwp app

Page 186: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Virtual Machines

Page 187: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

vagrantup.com

Page 188: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Virtual Machine(Virtual Server)

Page 189: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host MachineVirtual Machine(Virtual Server)

Page 190: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

PHP 7.1

Host Machine

Page 191: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

PHP 7.1

Host Machine

Page 192: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

PHP 7.1

Host Machine

PHP 7.1

Remote Server A

Page 193: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

PHP 7.1

Host Machine

PHP 7.1

Remote Server A

Page 194: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Remote Server B

PHP 5.2

PHP 7.1

Host Machine

PHP 7.1

Remote Server A

Page 195: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Remote Server B

PHP 5.2

PHP 7.1

Host Machine

PHP 7.1

Remote Server A

FatalErrorException

Page 196: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Virtual Machine A Remote Server A

Remote Server BVirtual Machine B

PHP 7.1

PHP 5.2

PHP 7.1

PHP 5.2

Page 197: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host machine uncluttered

Page 198: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host machine unclutteredSoftware versions contained

Page 199: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host machine unclutteredSoftware versions containedSimilar as possible to production

Page 200: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host machine unclutteredSoftware versions containedSimilar as possible to productionShared filesystem runs slow

Page 201: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Host machine unclutteredSoftware versions containedSimilar as possible to productionShared filesystem runs slowMemory hungry

Page 202: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

WHY IS THE RAM

ALWAYS GONE

Page 203: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Provisioning

Page 204: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

ansible.com

Page 205: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 206: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

php 7.1

Page 207: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

php 7.1php 7.1

Page 208: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

php 7.1

php 7.1

php 7.1

Page 209: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

php 7.1

php 7.1php 7.1

php 7.1

Page 210: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Provision servers with single command

Page 211: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Provision servers with single commandDescriptive configurations

Page 212: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Provision servers with single commandDescriptive configurationsIdempotency (same when repeated)

Page 213: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Provision servers with single commandDescriptive configurationsIdempotency (same when repeated)Reproducable servers

Page 214: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

roots.io/trellis

Page 215: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Multisite, wp-cli, etc

Page 216: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Multisite, wp-cli, etcDeploy script with build hooks

Page 217: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Multisite, wp-cli, etcDeploy script with build hooksActive open source community

Page 218: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Multisite, wp-cli, etcDeploy script with build hooksActive open source communityUsually does more than you need

Page 219: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Multisite, wp-cli, etcDeploy script with build hooksActive open source communityUsually does more than you needFiddly to update

Page 220: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ git remote add upstream https://github.com/ roots/trellis.git

Page 221: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ git remote add upstream https://github.com/ roots/trellis.git

~/site $ git remote -v origin [email protected]:chrissherry/site.git (fetch) origin [email protected]:chrissherry/site.git (push) upstream [email protected]:roots/trellis.git (fetch)

Page 222: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~/site $ git fetch upstream master

~/site $ git merge -X subtree=trellis --squash upstream/master

Page 223: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

MERGE CONFLICTS

MERGE CONFLICTS EVERYWHERE

Page 224: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

roots.io/trellis

Page 225: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 226: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Autoloading

Page 227: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

require_once dirname(__DIR__).'/vendor/autoload.php';<?php

/wp-config.php

Page 228: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 229: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 230: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 231: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 232: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 233: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 234: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Page 235: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ ChrisSherry $ WordPress for the modern PHP developer

Page 236: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

~ ChrisSherry $ WordPress for the modern PHP developer

Page 237: WordPress for the modern PHP developer

@tweetingsherry #phpuk17 You’re awesome

Thank you

Page 238: WordPress for the modern PHP developer

@tweetingsherry #phpuk17

Next Talks

Serving 30,000,000 Requests an Hour in the

Cloud

The road to continuous deployment: a case

study

It's all about the goto

Terrence Ryan Michiel Rook Derick Rethans

Main Track Sidetrack 1 Sidetrack 2