Migrating a WordPress blog to Heroku

Moved my blog from Godaddy to Heroku today.

There are several good blog posts about using WordPress + Postgres on Heroku, and in fact I did that at first. However, I could not find any info about migrating existing blog data from Mysql to Postgres.

Since I wanted to migrate my old posts I was pretty sure migrating the WordPress database from MySql to Postgres was likely to introduce some problems. So I used the relatively new Heroku MySql option, ClearDB (which also has a free 5 MB option if that’s large enough for you).

The basic steps were:

  1. using Phpmyadmin on Godaddy, I backed up the database (to SQL format, the default) and downloaded the .sql file to my desktop.
  2. Created a heroku app (cedar stack)
  3. Downloaded and extracted the wordpress code
  4. Did a git commit before fidding with settings
  5. Added a ClearDb database to the app
  6. Discovered the ClearDB login credentials

    Which displays
  7. Using those credentials, used Sequel Pro (http://www.sequelpro.com/) on my Mac to upload the .sql file to my Heroku database
  8. Copied wp-admin-sample.php to wp-admin.php and edited it with the database credentials
  9. pushed the revised code back up to Heroku
  10. For pre-existing images, I downloaded the wp-content/uploads directory, copied it to my local git repo, the re-pushed to Heroku.
  11. For new images, I downloaded the tantan-s3 plugin and installed it per directions… very nicely redirects uploads to my Amazon S3 account. (Of course, you could continue to manually insert images them by adding to a folder in the wp-content/uploads folder, then re-pushing the repo each time, but using S3 is easier.

That’s it, all my old blog posts were there.

I then added my domain name to my heroku app, changed my DNS to point to proxy.heroku.com, and it worked. (I did have to manually reinstall the plugins I was using. Since Heroku does not support unzipping library, you have to download locally, unzip, put in the plugins directory, then do another git push. Not too hard.)

If anyone else will see your git repo, you’d want to use ENV variables for your database password.

I also installed the WordPress SMTP plugin so mail is sent via an SMTP account instead of the php mail() function since that was causing some issues (system emails such as password reminders were not being sent). http://wordpress.org/extend/plugins/wp-mail-smtp/installation/

One more thing, if you are using permalinks…

Since Heroku will not permit the WordPress app to create/re-write the .htaccess file, you need to manually create the following .htaccess file then push to Heroku:

This entry was posted in Heroku, Web. Bookmark the permalink.

Comments are closed.