WordPress Development
and Deployment Strategies

David McDonald
November 13, 2013

http://www.dmcweb.com.au/wpmelb

I'm always looking for ways to optimise my workflow. Here are some strategies I have found to do that.

1. Dynamic virtual hosts on localhost

Useful when running multiple local websites.

Creating a new website is as easy as adding a folder to your webserver root.

The virtual hosts are created automatically.

How to set up:

Install dnsmasq & setup. Easiest install is to use homebrew:

brew install dnsmasq

Modify your vhosts.conf file:

<VirtualHost *:80>

VirtualDocumentRoot /Users/[myusername]/Sites/%1/

ServerAlias %1.*
UseCanonicalName Off

<Directory "/Users/[myusername]/Sites">
Options Indexes FollowSymLinks Includes ExecCGI MultiViews
</Directory>

</VirtualHost>

Edit your Network preferences and add 127.0.0.1 above any other DNS server entries

2. wpbuildr

Shell script that completely automates the set up of a WordPress install.

To create a new WordPress site, copy the conf folder into your new site folder, then run:

wpbuildr [sitename]

How to set up:

Clone from github: https://github.com/AaronHolbrook/wpbuildr

git clone https://github.com/AaronHolbrook/wpbuildr.git [mydirectory]

Follow instructions there and customise as needed.

Some of the wpbuildr forks and pull requests are interesting to look at for ideas.

3. Must Use Plugins

Are plugins installed in the mu-plugins directory inside the wp-content folder and which are automatically enabled on all sites in the installation.

Useful examples of mu-plugin use:

Caveat: mu-plugins are not checked for updates by WP's auto update

http://codex.wordpress.org/Must_Use_Plugins

4. WordPress Deployment with git post-receive hooks

Deploy Wordpress sites easily.

To deploy a site to the testing server:

git push test

To deploy a site to the live server:

git push live

Set up on the local site:

Set up an SSH alias for the site: in ~/.ssh/config:

Host website-l
Hostname www.website.com.au
user gituser

Set up on the remote site:

Set up a bare git repo and the post-receive hook:

mkdir website.git && cd website.git
git init --bare
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=~/www/wp-content/themes/[my theme name] git checkout -f
chmod +x hooks/post-receive

Back on the local site:

Add a remote repo:

git remote add live website-l:~/website.git
git push live +master:refs/heads/master

The remote repo lives in the ~/ of website-l, so it's not accessible to the world

The post-receive hooks pushes the bare files to ~/www/wp-content/themes/[my theme name]

All the above can be scripted as part of setting up a new site, using wpbuildr.

I found the concept at http://toroid.org/ams/git-website-howto

Thank you!

You can view this presentation at http://www.dmcweb.com.au/wpmelb