WordPress and Pow

Apple + WordPress = POW!

Here is my second take on running WordPress and WordPress Multisite locally on my Mac (first is here). I just discovered Pow; “Pow is a zero-config Rack server for Mac OS X. Have it serving your apps locally in under a minute”, and my first thought was “can I run WordPress on Pow?”.  Well, here’s how I did it (I’ll also show you how to install MySQL, PHP 5.4 and Ruby 1.93 on Mac OS X Mountain Lion):

This guide is work in progress, I’ll keep you updated on twitter

Prerequisite

  • Mac OS X Mountain Lion. I did this on a fresh Mac OS X Mountain Lion installation.
  • Download and install Command Line Tools (Mountain Lion) for Xcode. If you’re not already registered for a free Mac Developer account, do so.
  • Download and install Xquartz so that the png.h header exists for compilation of certain brews. Mountain Lion removes X11, which contained many headers.
  • Install Homebrew, “The missing package manager for OS X“. Open Terminal, and from the command line run:
    ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

There’s going to be a lot of cut and past from now on, but in 15 minutes you’re up and running with WordPress on Pow :).

One by one, copy the commands below and run them in Terminal

MySQL

When you run mysql_secure_installation (line 7 below), answer Y to all the questions.

brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
/usr/local/opt/mysql/bin/mysql_secure_installation

Add WordPress database and user to MySQL

mysql -u root -p

mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@localhost IDENTIFIED BY 'Pa$$w0rd';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

PHP 5.4

PHP is no longer part of the default Homebrew repository, and hence you need to add the Homebrew-PHP repository. WordPress and Pow only needs mysql and php-cgi. If you’d like to add more features, run brew options php54 from the command line to see the available configurations.

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54 --with-mysql --with-cgi

Ruby upgraded using rbenv

The default Ruby version on Mountain Lion is a bit old (yepp, that’s an understatement). Pow is a Ruby/Rack web server, and it runs best on the latest version of Ruby. rbenv in combination with ruby-build, allows you to install Ruby in your user space.

brew update
brew install rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source .bash_profile
brew install ruby-build
rbenv install --list
rbenv install 1.9.3-p327
rbenv rehash
rbenv global 1.9.3-p327

Pow and Powder

Pow was created to run Rails/Rack applications, but we want to run legacy applications on Pow (ie PHP / WordPress) and need the rack-legacy rack-rewrite gems.
Pow is easy, but Powder makes it even easier, with a lot of management commands for Pow.

gem install rack-legacy rack-rewrite
gem install powder
rbenv rehash
powder install

WordPress

Ta-da, finally there, just have to grab wget first.
The config.ru file, saved in ~/Sites/config, is a configuration file with rewrite rules (think .htaccess) for WordPress. At the moment it doesn’t support multisite, but I’m working on it. Forked the git below and added support for WordPress Multisite

brew install wget
mkdir ~/Sites
cd ~/Sites
git clone git://gist.github.com/4208560.git config
wget http://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz
mv wordpress myblog
cd ~/Sites/myblog
ln -s ~/Sites/config/config.ru
powder link
powder open

Adding another WordPress site

Yes, you can :)

cd ~/Sites
tar zxvf latest.tar.gz
mv wordpress myblog2
cd ~/Sites/myblog2
ln -s ~/Sites/config/config.ru
powder link
powder open

WordPress Multisite on Pow

I highly recommend that you create a separate database for your multisite, so let’s do that first

mysql -u root -p

mysql> CREATE DATABASE multisite;
mysql> GRANT ALL PRIVILEGES ON multisite.* TO wordpress@localhost IDENTIFIED BY 'Pa$$w0rd';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

next, install WordPress

cd ~/Sites
tar zxvf latest.tar.gz
mv wordpress multisite
cd ~/Sites/multisite
ln -s ~/Sites/config/config.ru
powder link
powder open

When you’re finished adding your site to the multisite database and it’s up and running, edit multisite/wp-config.php and add the following just above the line reading
/* That’s all, stop editing! Happy blogging. */

/* Multisite */
define('WP_ALLOW_MULTISITE', true);

You will need to refresh your browser to continue, then go to Tools > Network Setup.

In Network Setup, select Sub-domains (more about why, below), fill in the Network Details and click Install. On the next page follow step 1 and 2. You don’t need a .htaccess file, config.ru added above handles rewrites.

Why sub-domains:

In Pow, once a virtual host is installed, it’s also automatically accessible from all subdomains of the named host. For example, the http://multisite.dev/ virtual host added above can also be accessed at http://subdomain.multisite.dev/ and http://blog.multisite.dev/, which is perfect for a WordPress Multisite installation.

7 thoughts on “WordPress and Pow

  1. derry

    Hello, Thanks for this post. I executed everything in your tutorial and recieved this error message:

    Errno::ENOENT: No such file or directory - php-cgi
    ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-legacy-0.3.5/lib/rack/legacy/cgi.rb:58:in exec'
    ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-legacy-0.3.5/lib/rack/legacy/cgi.rb:58:in block in run'
    ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-legacy-0.3.5/lib/rack/legacy/cgi.rb:52:in popen'
    ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-legacy-0.3.5/lib/rack/legacy/cgi.rb:52:in run'
    ~/sites/phpapps/wordpress/config.ru:28:in run'
    ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-legacy-0.3.5/lib/rack/legacy/cgi.rb:23:in call' ~/.rvm/gems/ruby-1.9.3-p374/gems/rack-rewrite-1.3.3/lib/rack/rewrite.rb:20:in call' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:147:in handle' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:99:in rescue in block (2 levels) in start' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:96:in block (2 levels) in start' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:86:in each' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:86:in block in start' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:66:in loop' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:66:in start' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:13:in run' ~/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/bin/nack_worker:4:in '
    

    Any help would be appreciated.

    Reply
    1. Ben Taitelbaum

      I got the same error, so to fix it, I made sure that pow can see php-cgi:

      echo 'export PATH="/usr/local/opt/php54/bin:$PATH"' >> .powenv

      (where that directory is the output of dirname which php-cgi)

      Reply
  2. Jochen Fuchs

    Hi Per,
    thx for your great blog entry on behalf of WP on Mac! Unfortunately, when running the init script “mysql_install_db” I get an abort “[ERROR] /usr/local/opt/mysql/bin/mysqld: unknown option ‘–skip-bdb’” w/o the system tables being built, and I am currently unable to nail down where within “mysql_install_db” the mysqld option string is assembled in an obviously false manner. Any clue or heard about that before? Sorry for this… Am using 10.8.2 and completed all prerequisites mentioned in the upper part of your post.
    Thx & regards, Jochen

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">