So, you got WordPress running on Heroku already? Congrats! But what if you are primarily a Rails developer like me, and use only Pow for local app serving needs? Have no fear, there is a way to run WordPress as a Rack app, so Pow can serve it up for you.
Having a local installation is key when running WP on Heroku because, alas, Heroku’s php doesn’t have zlib compiled. This means you need to do all plugin installations and updates from your local environment, and deploy the changes.
To make WP work with Pow, we need to set it up as a Rack app. To do this, we can leverage the handy rack-legacy gem to parse the PHP content from within the ruby/rack environment.
Here’s the steps I took to get this working.
- You need a rack-up file to turn WP into a Rack app.
- I found one here, and then modified it a bit (following along with the comments on the original one).
- Here’s my config.ru with all modifications needed for WordPres.:
- The PHP version shipped with OS X doesn’t have php-cgi installed, which this approach relies on
- The app was returning blank pages or screens with no content
- Remember to do “touch temp/restart.txt” after any/all changes to your config.ru file
- Also remember you can check the pow logs with Mac OS X app: Console (look under ~/Library/Logs, Pow)
- Somewhere it was suggested that you can symlink the php binary to php-cgi…That did not work for me
- I tried using this set of steps to do another php build via homebrew:
- It downloaded some stuff, took a long time, and hit an error:
- “Undefined symbols for_xsltLibxmlVersion, referenced architecture x86_6″
- Google was no help on that one. Uninstalling/reinstalling libxml2 didn’t seem to help.
brew install php --with-mysql --with-cgi --with-gmp
- I don’t know what gmp is, and don’t care
- using –with-cgi gave me the php-cgi binary
- I added this to the bottom of my .bash_profile to ensure I hit the right binaries:
- export PATH=`brew –prefix php`/bin:$PATH
"Your heroku DATABASE_URL does not appear to be correctly specified."
- Right, this is the error we put in above, and we are getting it because we aren’t on heroku now
- Create your local db:
mysql -u root -p -e "CREATE DATABASE ;;"
echo 'export DATABASE_URL="mysql://root@localhost/repo-name"'
- Or, slightly easier, if you have my fork of powder installed:
powder env DATABASE_URL mysql://root@localhost/repo-name
mysqldump --host us-mm-auto-dca-01.cleardb.com --user 4ecf8dbd0f00b7 --password=3b2e4402 heroku_fd542dc123475e0 | mysql -u root -p ;
- Before running this, put the app in maintenance mode so the db won’t change:
- Sign in at http://local-app-name.dev/wp-login.php with the same user you set up on production.
- Now you can install and update plugins, add themes, etc.
- When you are done: commit, deploy, push the db back up with by reversing the dump command, and switch the app back on…
git commit -am "Updated this AND that\!"
git push production master
mysqldump -u root LOCAL_DB_NAME | mysql --host us-mm-auto-dca-01.cleardb.com --user 4ecf8dbd0f00b7 --password=3b2e4402 heroku_fd542dc123475e0
Other issues you might run in to:
- Heroku reports “No such file or directory – php-cgi”: I hit this when I included a Gemfile that contained rack-legacy. Restricting it to the :development group enabled me to get to the next error…
- App dies, and Heroku logs say “can’t find executable rackup”: Looks like WP on Heroku just doesn’t want to work with anything in the gemfile. Deleting Gemfile and Gemfile.lock from the repo, and adding both to .gitignore got the app going again on Heroku. Any ideas why this is happening? I’d love to hear a better work-around.
- Pow reports: “LoadError: cannot load such file — rack-legacy” (or just rack). It seems to me a newer version of RVM caused Pow to not get the right gemset. There are lots of suggested fixes, but this one is what worked for me (followed by .gitignore’ing my .powenv file, which is the right behavior anyway).