WordPress on Heroku: Up and Running!

 

Heroku is a great service, and simply the best way to quickly deploy small apps into a production environment. I usually use it for Ruby on Rails apps, but every now and then, a WordPress installation is more suited for a particular project. Now that Heroku supports php, WP can be deployed to the cloud in just a few steps.

Caveat: Without zlib, Heroku’s php platform is unable to handle the installation or upgrading of themes or plugins, so those tasks need to be managed in a local development environment, and pushed to production via Heroku’s slick git deployment. It’s inconvenient, but I’m working on some tools to make it smoother. Once you are up and running, see the followup post for details about what’s required.

Here’s the step by step tutorial for getting a WordPress.org installation running on Heroku’s Cedar stack.

  1. Create GitHub repo
  2. Then create local repo with GitHub as the upstream for origin. Basically like it says on the new repo page:
    1. cd REPO-NAME
    2. mate README.markdown # Create the readme file... use your favorite editor. Put in something informative
    3. git add .
    4. git remote add origin git@github.com:brookr/REPO-NAME.git
    5. git push -u origin master
  3. Download the latest wp.org source into your local repo.
    1. The zip download will extract contents into a ‘wordpress’ folder
    2. move the contents of that folder into your repo dir.
  4. Create a heroku server on the Cedar stack
    1. gem install heroku # If you don't have it already. Use `sudo` if you aren't using RVM
    2. heroku create --stack cedar --remote production
    3. heroku rename REPO-NAME # Or call it whatever you like for your project
    4. Verify that the production remote in .git/config was update with the new name
  5. Configure the heroku server with some handy free add ons:
    1. heroku addons:add stillalive:basic
  6. Most importantly, add a MySQL database option. There are 2 possibilities. Let’s try ClearDB, as the pricing scales better for low-volume sites:
    1. heroku addons:add cleardb:ignite # Adds the MySQL option to the Heroku app's config
    2. heroku config # See the URLs for your new databases
    3. heroku config:add DATABASE_URL=mysql://... # Replace the "mysql://..." with the URL from CLEARDB_DATABASE_URL
  7. Configure WordPress
    1. Set WP to connect to your database, by replacing the contents of wp-config-sample.php with this:
      if (isset($_SERVER["DATABASE_URL"])) {
       $db = parse_url($_SERVER["DATABASE_URL"]);
       define("DB_NAME", trim($db["path"],"/"));
       define("DB_USER", $db["user"]);
       define("DB_PASSWORD", $db["pass"]);
       define("DB_HOST", $db["host"]);
      }
      else {
       die("Your heroku DATABASE_URL does not appear to be correctly specified.");
      }
    2. Update the secret key section of the config with settings from: https://api.wordpress.org/secret-key/1.1/salt/
    3. Add some deployment-awareness, so links will work locally as well as in production:
      • define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] );
    4. Rename the file with git:
      • git mv wp-config-sample.php wp-config.php
      • git commit -am "Initial config file reading heroku ENV"
  8. Deploy!
    • git push production master
  9. Congrats, you are up and running! You can now configure your site:
    1. heroku open
    2. Enter info for the Site and initial admin user

Now you gotta get your local dev environment setup. Here’s how I did it, using the POW web server.

 

26 Responses to “WordPress on Heroku: Up and Running!”

  1. JohnTheBastard February 25, 2012 at 1:04 am #

    Excited about this. Will give it a go tomorrow.

  2. rojita June 3, 2012 at 3:52 am #

    Thanks for this information. Where exactly do you put the wordpress directory in your repo? Does it go into public? Thanks for your help.

    • brookr June 4, 2012 at 11:19 pm #

      I presume you mean the /public folder of a Rails app? Alas, that’s not how this works. Heroku can’t mix different languages in the same deployment. So, for WP to run on Heroku, it has to be a php-only repo. The root of the WordPress installation is the root of the heroku project. Sorry for any confusion!

  3. Ren July 7, 2012 at 4:00 pm #

    Thanks! This worked like a charm! I’m curious why you decided to go with cleardb instead of something like Amazon RDS or PostgreSQL?

    All in all, great show!

    I’ll be getting started on getting this running in a local env *crosses fingers*

    • brookr August 31, 2012 at 1:56 pm #

      Hi Ren—

      Alas, WordPress does not work with PostgreSQL, and Amazon RDS is another layer of complexity and costs.

      ClearDB has a reasonable free plan, and offers automatic integration with heroku via the add-on installation process.

  4. Andrew July 30, 2012 at 7:25 am #

    Thanks for the clear walkthrough, very helpful. Looking forward to what you have to make plugin update/install smoother.

    • brookr August 31, 2012 at 2:00 pm #

      Hi Andrew—

      This is what I have worked up so far:

      https://github.com/brookr/heropress

      It’s pretty basic, but allows you to do quick db imports and backups from the local or production db. That means I can pause the app, pull the remote db to overwrite my local, update plugins locally, then deploy by pushing code & db, and unpausing the app.

      Not quite seamless, but usually it’s not more than a minute or two of downtime.

  5. Cliff September 6, 2012 at 3:25 pm #

    So I have a question about your media uploads Directory in this implementation. I have found that when I upload images to the WP site non local the images on Heroku get deleted if I restart Heroku. Is their a known work around for this besides housing images and media on an external Cloud storage like AWS or trying to force the media into the DB?

    • brookr September 21, 2012 at 11:29 pm #

      Right! This is a sticky point. I think i’d recommend doing all media via AWS or similar. There are plugins to support this.

      The other option is to do all media uploads locally, so files are processed and stored in your local file system. Then you can add them to your repository, and push them to heroku. You’ll also need to sync & push your db. They will be available to all dynos, and will survive across deployments and server restarts.

      The little heropress lib i’m working with makes this slightly easier to manage: https://github.com/brookr/heropress

      • MASAHIRO December 10, 2012 at 7:05 am #

        thanks for your explanation.if you know,i want to know. so why uploaded media is deleted? because not commit?
        keep in touch.

  6. VM October 14, 2012 at 8:28 pm #

    Hi, what is the advantage of running wp on heroku? is it something like staging-live environment?
    How much did you pay?
    thanks

    • brookr October 17, 2012 at 3:32 pm #

      Hey VM—

      I run live sites and blogs on WP on heroku. There is a little more overhead if you are doing a lot with WP, but it’s otherwise free, stable hosting that can handle a lot of traffic (especially with a few caching plugins). I haven’t paid anything yet. Maybe if a database grows large, I’ll need to upgrade the db plan, but otherwise, costs should be really low.

  7. Erick December 26, 2012 at 2:03 pm #

    Hey Brookr, I appreciate the blog post, I am new to all of this (heroku, github) but Ive been able to make it up to step 3. I dont understand what you mean and how to to do it, when you write move the contents of that folder into your repo dir. (on step 3). Thank you

  8. dearwish May 6, 2013 at 3:11 am #

    Worked for me just great, thank you.

  9. Jason September 12, 2013 at 2:16 pm #

    I have followed all of the steps outlined here, I was able to successfully deploy wordpress to heroku, but when I try to visit the site, I get a 500 error.

    I wonder if there is an issue with the wp-config file here is what I have http://d.pr/n/LWOW

    Here is my log file via papertrail http://d.pr/n/LgAx

    Any help would be greatly appreciated.

Trackbacks/Pingbacks

  1. WordPress on Pow: Rack-powered WP | Wisps & Snippets - March 1, 2012

    […] on March 1, 2012 by brookr in Freelancing, WordPress on Heroku 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 […]

  2. How to put WordPress on Heroku | hish’s Weblog - June 20, 2012

    […] WordPress on Heroku: Up and Running! | Wisps & Snippets. This entry was posted in Uncategorized and tagged heroku, web development, wordpress by hish. Bookmark the permalink. […]

  3. Deploying WordPress to Heroku was a success | hish’s Weblog - June 21, 2012

    […] found these instructions that worked with WordPress 3.4. They were easy to for me follow and thorough – no other […]

  4. WordPress | Synapse du jour - July 24, 2012

    […] WordPress on Heroku […]

  5. WordPress: Is it possible to host a wordpress blog with launcheffect for free on heroku? - Quora - September 6, 2012

    […] Mourlevat, Mahi-Mahihere is a clean tutorial to host a WordPress on heroku : http://decielo.com/articles/350/…can't see a problem for enabling launcheffect plugin on it.Embed QuoteComment Loading… • […]

  6. Hello world! ← ioxdue - October 4, 2012

    […] WordPress on Heroku: Up and Running! […]

  7. WordPress on Heroku: Up and Running! ← ioxdue - October 4, 2012

    […] WordPress on Heroku: Up and Running! […]

  8. Heroku push rejected, no Cedar-supported app detected wordpress - feed99 - December 3, 2012

    […] I’ve been trying to deploy wordpress onto a heroku app using the tutorial @ http://decielo.com/articles/350/wordpress-on-heroku-up-and-running […]

  9. Hello world! | KIERAN DENSHI DOT COM - January 25, 2013

    […] running on Heroku! Many thanks to the author of this article for showing the […]

  10. spencerenglish.com - February 7, 2013

    […] process. It started by telling the user to create a new Facebook app… anyway, after I found a good article, I was set to […]

Leave a Reply