WordPress on OS X with Nginx, PHP, and mysql


Recently, I wanted to do some WordPress development on my Mac.  I’ve got Ubuntu installed on a virtual machine, but I decided to get the stack running on OS X.

I’ve been using Nginx for a while now as a web server, caching proxy, and load balancer for some Plone sites.   It’s been fantastic – fast, reliable, easy to configure – greatly simplifying my life as a sysadmin.  I was interested to see how it would work for serving wordpress.

If you haven’t checked out homebrew, you should.   No, it’s not beer, but a package manager for OS X.  Homebrew is, they claim and I agree, the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X.

First, install and start the mysql server:

brew install mysql
/usr/local/bin/mysqld_safe --datadir=/usr/local/Cellar/mysql/5.5.10/data

Installing PHP is a little more complicated, since there isn’t an official homebrew formula. Instead, grab this formula:

wget https://github.com/ampt/homebrew/raw/php/Library/Formula/php.rb
mv php.rb `brew --prefix`/Library/Formula

Then, build PHP with mysql and fastcgi support:

brew install php --with-mysql --with-fpm

Tell PHP to listen on port 9000:

/usr/local/Cellar/php/5.3.6/bin/php-cgi -b 9000

Installing nginx is as simple as:

brew install nginx

You’ll need to modify the nginx.conf, which can be found in /usr/local/etc/nginx, and add this configuration:

server {
    listen       8080;
    server_name  localhost;

    location / {
        root   /path/to/wordpress;
        index  index.php index.html index.htm;

    location ~ .php {
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /path/to/wordpress/$fastcgi_script_name;

Start the Nginx server like this:

/usr/local/sbin/nginx -c /usr/local/etc/nginx/nginx.conf

There are more robust ways to start these services, but since this is just a development environment, I prefer not to have them running unless I am actively working with them. Now you should be ready to install WordPress.  Happy developing!