Running WordPress on Nginx

Hopefully, this is old-hat to many of you by now, but trying to figure out how to get my Apache configs to play nicely with my Nginx configs on my local dev machine has proven – shall we say – challenging. I had a need to spin up my WordPress instance locally for some theme and plugin development a couple months ago and decided to bite the bullet and just get it running on Nginx so that I didn’t have to switch server contexts between my PHP and Node.js projects.

It took me a little time to work out all the nuances, but when everything was said and done, it really wasn’t very hard. For me, I generally set up a dev.* subdomain on my local box for whatever site I’m currently working on. So, if I’m actively developing my site here, I usually start with simply verifying my /etc/hosts entry (sorry PC users, I’m working Mac all the way here):

Once you’ve registered your hosts, requests to the specified domain will be routed to that IP address (localhost). So, now, we need to be sure that we have something able to listen on port 80 to resolve those requests. In my case, I like to create a new server conf file for any new projects I’m wanting to run locally. In this case, I’ll create a new file here:

The following config is pretty self-explanatory, but we will look at it in a little depth:

The first section to call out is where we tell Nginx the order in which to look for index files in our directories. Immediately after, we include a conf file we have created explicitly for PHP handling:

The php-fpm file essentially tells Nginx how and where to process PHP requests via FastCGI:

This config assumes you’re running FastCGI on the default port 9000, obviously. Once this is set up, you can restart Nginx, and requests to your host will begin flowing.

In order to get the WordPress piece working well, I just needed to reflect some of my Apache mod_rewrite rules here in Nginx. That is what the following lines are doing:

With this redirect in place, all routes will be passed through to the WordPress query parser at index.php.

That’s really all there is to it! With your configuration set up and Nginx restarted, WordPress will be served locally mirrored to the previous Apache behavior.

Testing Hapi Plugins

Recently, I have found myself needing to build out some authorization modules for both Hapi and Express applications. Hapi has become my server of choice, and building some fully testable plugins has been a priority. In the process, I have learned several techniques that have really streamlined my testing.

There are a few tools I’ve settled on for the baseline structure of my testing:

Test runner and base framework
Chai (Chai.expect)
Assertion library
Mocks, Stubs, Spies and many other useful helpers
Simplifies assertions against explicit routes in our server
Mocks Node’s HTTP request library for injection of responses

Continue reading →

PHP Routing Library

For the past few years, I have been working more and more with Node.js and proportionally less frequently with PHP. As might be expected, though the underpinnings of web behavior is platform agnostic, the architecture for the web application layer changes to suite the technology stack in which you are building. In fact, one of the marks of a savvy engineer is the ability to leverage the best parts of a technology in the way they build their software. However, I found myself spending far too much time trying to relearn techniques in PHP for projects as I came back to them, so I decided to see if I could build a lightweight routing system in PHP that would mirror some of the patterns I use in my Node.js work every day.

Anyone who has worked with Express, Hapi, Django, Rails or even Grails can understand the ease of route declaration with something like this:

Continue reading →

Tracking Room Usage

At work, my team has been working on an extremely intriguing project to see whether or not we could devise a solution to allow us to accurately track the usage of our meeting rooms. The initial project was intended to simply help individual contributors find a currently open space in which to meet with a coworker for an impromptu meeting, but it has grown into much more. As the data has started rolling in, we are discovering the ability to analyze room usage and actually advice facilities management on which areas could stand some additional optimization.


Charted above is an example of the data we have been able to start visualizing. While I cannot share actual internal Disney data, this sampling is  representative of the type of metrics we are gathering. Interestingly enough, when we overlay the data collection with the bookings of the rooms in Outlook, we can start identifying trends with people who might book rooms on recurring schedules but seldom use their allocated time.

Continue reading →

Client Side Testing: a Baseline

Those who well know me and my work understand my passion for coding things right the first time. Take a little extra time to architect something, and you will save yourself hours, days or – in some cases – weeks of development time down the road. What better way to assure your code is meeting your own exacting standards on the client layer than to establish some good testing practices.

In an attempt to aid developers with less testing experience in setup and execution of client testing, I have created a new repository on Github to help with a testing baseline from which each can develop his own processes: Client Testing Baseline.

The only prerequisites is installation of NodeJS. See the README file in the repository for details on what test environments and additional code assistance tools are included.

Triggering True onChange Event for Text Fields

Something I’ve run into on multiple occasions is the desire to be able to trap the change event of text fields and textareas – not just on blur but when their value actually changes. I will assume some basic understanding of how DOM elements behave and that, while the input and textarea nodes have change events, they don’t actually fire in all browsers until you move away from them. This led me to thinking that there has to be a somewhat optimal way to trigger an event on those fields only when their value changes. If you’ve ever tried something like this before, you may have settled for a combination of listening to keypress and keyup events to get your desired behavior across all browsers, but once again, you have to attach this to all. elements on which you wish it to behave. jQuery once again allows us to develop a very simplistic solution in a relatively tiny bit of code:
Continue reading →

WordPress Plugin: Ajax and WYSIWYG Comments

I spent a good bit of time on Google and the WordPress Codex trying to figure out the best way to customize comments to use Ajax for posting. I finally decided to write my own plugin to solve the issue, since there are a lot of ideas but no real concise nor comprehensive solutions that worked across the board. Additionally, I wanted to offer the capability of using a custom version of the built-in WYSIWYG editor (TinyMCE) to users for comment modification as well. If you have some time to check it out and leave me some feedback, I would appreciate the input!

Custom Google Voice Widget Creation

If you use Google Voice, you may be familiar with the option of creating widgets that you can place on your website which allow people to enter their phone number and request to be connected to your Google Voice number. There are several benefits to this type of behavior, but the best of these is that you can offer people the opportunity to call you without ever publicly displaying your phone number. What’s more, each new widget creates a unique buttonId associated with it that allows you to record a custom voicemail response for users of that widget.

Of course, the downside to use of the widget system is that it is not customizable at all, and it is only available in the form of a rather large Flash button to place on your site. After some digging and research, I finally figured out how to post requests to your unique buttonId via standard HTML forms. Taking this to the next level (and much more usable, I might add) lets us create a manual Ajax handler that will make our request to connect the user without ever leaving our page.
Continue reading →

A Starbucks Conundrum

Something I have noted in my relatively regular visits to Starbucks for my morning dose of goodness-in-a-cup is the nearly overwhelming mispronunciation of the 20oz drink option. As you may or may not be aware, this size designation is a venti, which actually means “20”. We can also see that the pronunciation, as expected, rhymes with tee or bee, but the baristas who serve me inevitably repeat my drink order as a vente instead. I was bothered by this for a while – up until the cleverly disguised sarcasm began to sink in. Wittingly or not, each of these baristas has just confirmed that I indeed had paid for a “wait” with cream, allowing them to take as much time as needed to prepare – since that is what I asked for after all. Kudos to you, Starbucks, for coming up with a naming convention that, however pronounced, will make me happily vente for my venti.

Seahawks, Packers and Refs: Oh, My!

I was one of the stunned Seahawks fans left in a very uncomfortable position after Monday night’s contested win against the Green Bay Packers – excited over the win but with a sour taste over how it went down. If you’re living under a rock somewhere and haven’t heard about the controversy, or if you simply care absolutely nothing for football and are reading this out of sheer boredom, let’s review the tension in the league building up to this climactic altercation.

Back in August the NFL refs union began negotiating with the NFL once again, but as everyone in the football world can tell you, it was too little, too late. The season began with the NFL bringing in inexperienced replacement refs who have been, shall we say, struggling to meet the challenge and call clean games – though in their defense, I’m sure they’re doing the best job they can under the circumstances. Suffice to say that there has been tremendous pressure poured out on these refs, and they have been the focal point of mounting tensions as questionable calls have been piling up during these first few weeks of the season.
Continue reading →