PeterJohn Hunt

5 Tips to Automate Your Post Launch Local Development

1) WP-CLI YML Aliases

Use WP-CLI aliases to quickly run commands in your other environment like DB exports, plugin activations, etc.

Documentation:

Example:

wp @production option get home

2) WP-CLI Bin scripts & Terminal Aliases

Building on WP-CLI Aliases, you can then build some custom bash scripts to easily re-run automated tasks like pulling down the latest DB from production

Examples:

Live to staging

mkdir db
wp @production db export - > db/production.sql
wp @staging db export - > db/staging.sql
wp @staging db import - < db/production.sql
wp @staging search-replace PROD_DOMAIN STAGING_DOMAIN
wp @staging option set blog_public 0
wp @staging plugin deactivate autoptimize
wp @staging cache flush

db-sync

mkdir db
wp db export db/backup.sql
wp @production db export - > db/latest-db.sql
wp db import db/latest-db.sql
wp option set blog_public 0
wp plugin deactivate autoptimize
wp cache flush
wp rewrite flush

You can also build some quick bash aliases to quickly navigate around through your sites:

Aliases

alias theme='cd wp-content/themes/$(wp option get stylesheet)'

alias site='cd $(wp eval "echo ABSPATH;")'

3) .htaccess

.htaccess allows for a quick hack to pull uploads directly from your production site

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^LOCALSITE$
RewriteRule ^.*/(uploads/.*)$ https://PRODUCTIONSITE/wp-content/$1 [L,R=301,NC]
</IfModule>

4) Publish Commands

Utilizing a couple custom commands and CI, you can standardize and organize your deployment to different environments while benefiting from things like an automated changelog or release notes!

Documentation:

5) CI Deployment

Seriously, CI deployment is amazing. i know some services have it automatically, like Pantheon, but to be able to add custom asset building, performance tweaks etc is a tool you’ll forever be grateful for once put into place!