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
- 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
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 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
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.
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.