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) mkdir MYBLOGDIR cd MYBLOGDIR git init heroku create MY_BLOG_APP_NAME –stack cedar
  3. Downloaded and extracted the wordpress code wget http://wordpress.org/latest.tar.gz tar xzvf latest.tar.gz; mv wordpress/* . rmdir wordpress
  4. Did a git commit before fidding with settings git add . git commit -am “first checkin” git push heroku master
  5. Added a ClearDb database to the app heroku addons:add cleardb:ignite
  6. Discovered the ClearDB login credentials heroku config

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 git add . git commit -am “added db credentials” git push heroku master
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:

# BEGIN WordPress
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 # END WordPress