My Dev Setup, part 4: Version Control and Deployments with WordPress

In an earlier post, I promised to shed some light on our git workflow for WordPress projects. The above image sums it up pretty nicely, but read on for the details.

Most of the development we do happens in a local Apache + PHP + MySQL environment, using MAMP Pro. That means I have a local copy of each site I’m developing, which creates some overhead compared to everyone just working on a central dev server. It’s worth it though because it makes working on different features and code branches easy.

Repository structure

Every project has its own git repository, which we set to the WordPress root directory. This is because most of our projects involve a combination of custom themes and plugins, and it makes sense to group them in a single repository. We still don’t want any of the core WordPress code in git, so we use a .gitignore file based on this excellent template by Joe Bartlett:

The above means that in practice the contents of a typical project repository structure looks somewhat like this:


/
+-- wp-content/
    |-- plugins/
    |   +-- custom-plugin/
    |
    +-- theme/
        +-- custom-theme/

Sharing code and automated staging with Beanstalk

When I want to share code with my colleagues or am ready to something to a client, I do a git push to a central repository hosted on Beanstalk. Beanstalk has loads of useful features, but the best thing about it has to be the simple deployments it offers. For all projects, we set up automated deployments to a staging server, where we have copies of each site. Deployments to production are also set up in Beanstalk, but (intentionally) require a manual click in the web app.

Going to production

Finally, moving from staging to production can require some tricky search-and-replacing domains and absolute paths in the database. WordPress in Network mode tends to be particularly keen on saving the site URL in way too many places. One way to do this is to perform a search and replace on a SQL dump, but we use this nifty tool by Interconnect/IT, because it correctly handles serialised strings, which are often used in WordPress for things like widget options etc. The same tool is useful when doing the reverse, ie. creating a local copy of an existing site.

Relevant links:

My Dev Setup, part 2: Web Development Apps for Mac OS X

In the second post of my “set up” series, I’m listing some of the apps I use daily for web development. The first part dealt with utility apps.

There are a multitude of tools available, and the specific ones you need will inevitably vary based on the kind of development you do, the languages you use, size of team etc. I do mostly front-end dev and WordPress theme + plugin development in a small team, so my choice of apps obviously reflects this. Also keep in mind that the industry is moving fast and in 12 months time we might all be using an entirely different set of tools.

Text Editor: Sublime Text 2

Sublime Text 2

I’ve written about Sublime Text in an earlier post, but I’m still going to mention it. It’s one of the best code editors out there at the moment, if not the best. Highly extensible, there are plenty of good additions relating web development and WordPress.

Get Sublime Text 2 here: http://www.sublimetext.com

CodeKit for Sass & Compass

Codekit

Sass is a robust CSS preprocessor that runs on Mac, Windows and Linux/Unix, and I’ve used it pretty heavily for the last 2 years. It allows extending CSS with variables, nested rules, logic, inheritance and mixins, among other neat things. It can be installed and run just fine from the command line as a Ruby gem, but recently we’ve started using Codekit, a marvellous app which takes care of compiling Sass (or Less/Stylus/HAML/Coffeescript etc) into final code in a nice, GUI-configurable fashion. It will also refresh your browsers automatically on save, combine + compress JavaScript and even optimise image files.

For an introduction to Sass, go to http://sass-lang.com/

Codekit ($29) http://incident57.com/codekit/

Version Control: Tower & GitBox

Tower screenshot

After having used Git for the last couple of years, it’s almost hard to imagine web development without some kind of version control. Learning at least the basics of git on the command line is most certainly recommended, but day-to-day I find a good GUI client is very handy. For many small projects the simple and elegant Gitbox (http://gitboxapp.com/, 13.99 € on the Mac App store) is quite enough, but for most projects I use Tower (http://www.git-tower.com/, 49.00 €).

I’ll be expanding on how we use Git in WordPress projects in a later post.

Diff with Kaleidoscope

Kaleidoscope screenshot

Sometimes (ie. often) you get conflicts when merging somebody else’s code with your own. A good merge tool helps, and for the Mac you can use either the free FileMerge included in the Mac OS X Developer Tools, or the excellent Kaleidoscope. Kaleidoscope used to be just a really good (and pretty) file comparison tool, but in its latest version 2 beta it includes merging capabilities for text and folders.

Download the trial here: http://www.kaleidoscopeapp.com/

PHP Error Monitoring: Console

console

Thanks to my excellent colleague Marco, I’ve discovered how useful the built-in OS X Console.app can be for tracking down PHP errors when doing local WordPress development. This allows you to easily view any errors without printing them out using WP_DEBUG and messing up everything.

MySQL Admin: Sequel Pro

Sequel Pro

For both local and remote MySQL administration, there’s nothing better than Sequel Pro. And it’s free.

http://www.sequelpro.com/

WP-CLI for command-line WordPress

WP Cli running in a terminal

When developing multiple WordPress sites locally or remotely, activating and deactivating plugins and themes via the admin interface can become tedious. For geeky-minded people, there’s WP-CLI, a simple command-line interface for creating and managing WordPress installations. Quoting from the website:

You can update plugins, set up multisite installs, create posts and much more.

http://wp-cli.org/

That’s all! In the next post in this series, I’ll look into my browser testing setup.

My Dev Setup, part 1: Utility Apps

This is the start of a series of posts on my current web dev setup. The various software I use, how it’s set up etc. Being a big nerd, I enjoy reading descriptions of peoples’ work environments, and I figured it was my turn to chip in. In this first post, I’m starting with a bunch of nifty utility apps that help me stay productive. Unfortunately only some of them are free, but I find in general you get what you pay for, especially when it comes to Mac OS X apps.

An app launcher: Alfred

Alfred screenshot

Alfred is a beautiful, minimalist and fast app launcher for OS X which I’ve been using for the last year. In addition to launching apps, it can be used for search (like Spotlight), clipboard history, controlling iTunes and many many other things. Alfred is free, but the Power Pack extension costs GBP 15.

Dropbox

dropbox icon

Dropbox probably doesn’t need an introduction. Since its launch, I’ve used it to sync files between my own computers and share files with colleagues and clients. I still use it extensively, but for some work activities it has been somewhat replaced by git version control and Basecamp. To get 500 MB extra, use my referral link: Get Dropbox

BetterTouchTool

Better Touch Tool Screenshot

If you have an Apple laptop, a Magic Touchpad or Magic Mouse (or all three), BetterTouchTool has some nice options to configure gestures and keyboard shortcuts. It also gives you window snapping à la Windows 7. And it’s free!

iTerm

iTerm icon

I recently discovered iTerm. It’s basically an alternative to the built-in Terminal.app, and mostly I don’t find them that different from one another. The thing that won me over was the split-pane view, which is especially useful in full screen mode.

TextExpander

TextExpander screenshot

For all sorts of reusable text and code snippets, TextExpander is indispensable. There’s also a great TextExpander tutorial on TutsPlus.

PathFinder

Path Finder screenshot

The default OS X Finder is OK, but Path Finder is the same thing on steroids. Obviously meant for power users, it has (among other things) a built-in terminal, dual-pane file browsing, Git & Subversion support, batch renaming etc.

That’s all for now, to be continued!