Last Updated: February 25, 2016
·
1.158K
· ericrallen

Improving WordPress Local Development Startup Time

NOTE: This Pro-Tip is specific to OSX, but you could probably adapt most of it to a Windows workflow, minus the AppleScript for xip.io URLs. Also, I'm not exactly great with shell, so if you have improvements to these simple aliases please share them, I'm hoping this will spark someone much smarter than me to create a better tool for packaging this functionality into a more robust command.

I've been using some bash aliases to automate the setup of local WordPress sites and wanted to share my setup and process.

This sets you up with a workflow that basically goes like this:

  1. Create database for local WordPress site
  2. Create directory for local WordPress site
  3. Type command in Terminal
  4. Answer questions about how you want WordPress set up
  5. WordPress is downloaded, wp-config.php is set up, and custom theme is installed
  6. Browser window opens to WordPress install page
  7. ...
  8. Profit

When you tell YeoPress what domain your site will be available at, use the .dev domain that pow will generate. It will be [your directory name].dev.

Then I usually just drag the directory to CodeKit and start developing on my local WordPress site and watch the changes happen live.

It takes about 1 minute to go from creating the directory to being able to start editing my theme and watch the layout changes occur in real time.

Before we begin

First, you will need to have some things configured in order for this to work, it is a bit of set up time, but once it's all configured the gains are totally worth it.

  1. Install Yeoman npm install -g yo
  2. Install YeoPress npm install -g generator-wordpress
  3. Install pow curl get.pow.cx | sh or Anvil
  4. Set up pow and apache to play nice
  5. Set up pow to be capable of hosting PHP files
  6. Save pertinent config files (more information on these below)
  7. Install powder gem install powder (you can skip this if you don't want to automatically generate your .dev links and open the /wp-admin/install.php after generating your site.
  8. Optional: Set up PHPMyAdmin if you prefer to have a GUI for creating your databases. As long as you followed the apache and pow playing nice instructions above you won't have to worry about stopping pow every time you want to use PHPMyAdmin.

The config files

We'll be symlinking a config.ru file that tells rack how to deal with our PHP sites; a config.rb file that sets up our site for Compass so you can just add the site's directory to CodeKit, Scout, Mixture, or just set up watching via the command line; and I also symlink a xip.io.scpt file that makes it easier for me generate xip.io URLs to my local sites so I can share a link with my coworkers and they can see the current progress and I can easily test the site on mobile devices with these links, too.

config.ru

You can get the original config.ru file we'll be using from this gist, and I created an alternate gist of the config.ru that has one line that was preventing my CSS and JS files from loading commented out. If the original is giving you issues, try it with mine.

config.rb

You can use any config.rb file that has the settings you want, I have one tailored to the base theme that we install on all of our sites, which I also tell the yeoman wordpress generator to download from GitHub and install into the correct theme directory for me.

I guess if you're a command-line SASSer you could tell SASS to watch the directory in the alias, too.

You can totally skip this file if Compass and SASS aren't your thing.

xip.io.scpt

You can also skip this if you don't care about being able to send links across your network and pull up the .dev domains that pow generates on mobile devices.

If that does interest you, here's the AppleScript file for you.

Storing these files

I prefer to keep them in ~/Sites/config/ but you can adapt the aliases below to point to wherever you'd like.

The bash aliases

Because I'm not always dealing with WordPress, I set up two aliases.

One starts with the WordPress generator, initializes git flow, then performs my symlinking, and opens up the .dev domain in my browser via powder.

The other excludes the WordPress generator and the git flow initialization.

NOTE: YeoPress can initialize a git repo for you, but I had issues with the generator hanging every time I tried to initialize git through it. If you don't have this problem, I'd just let YeoPress do it for you since you'll be answering it's set up questions anyway.

fireitup

alias fireitup='ln -s ~/Sites/config/config.ru; ln -s ~/Sites/config/config.rb; ln -s ~/Sites/config/xip.io.scpt; powder link; powder open'

wpfireitup

alias wpfireitup='yo wordpress; git flow init; fireitup'

I'm not shell expert, so I'm sure you have ways of improving these aliases, and maybe even combining them into one command with parameters, so please share them in the comments.

I would really like to improve upon them.

xip.io

There's a post detailing my xip.io.scpt AppleScript and the xipit alias that I use to run it if that interests you. If you don't care about that functionality you should remove the ln -s ~/Sites/config/xip.io.scpt; from the fireitup alias.