Knowing that there are plenty of pages out there to walk you through the exact same thing, I won’t make this guide too long: only five steps, with some bullet points for future reference.
1. Create a Heroku project
- Create an empty folder, locate it in Terminal and:
$ git init
$ git add .
$ git commit -m "init"
$ heroku create
- Setup the name of the Heroku app and make your domain point to it
- Add a ClearDB database to this Heroku project
2. Make a copy of your WordPress site
- Download all WordPress files and copy them to the Heroku project’s folder
- Create a dump of the database (the easiest way is to use this WordPress backup plugin)
- In the Heroku project, make sure all domain values in the files’ content point to the right address. I had quite a few ‘hardcoded’ values in the footer still pointing to wimagguc.hu – a quick search and replace on all textual files took care of this.
- Pro tip: if you had a .htaccess file, make sure to copy that as well
3. Migrate your database to ClearDB
- Connect to ClearDB via MySQL Workbench (or a similar tool), and import the SQL dump you created in step 2.
- Your articles and settings will still point to your old domain. Fix these with three simple updates:
UPDATE PREFIX_wp_options SET option_value = replace(option_value, 'www.OLD-DOMAIN.com', 'www.NEW-COMAIN.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE PREFIX_wp_posts SET guid = replace(guid, 'www.OLD-DOMAIN.com','www.NEW-COMAIN.com');
UPDATE PREFIX_wp_posts SET post_content = replace(post_content, 'www.OLD-DOMAIN.com', 'www.NEW-COMAIN.com');
- Edit your wp-config.php:
$db = parse_url($_SERVER["CLEARDB_DATABASE_URL"]);
4. Make The Heroku project run locally
- (Now this step is far from mandatory, but I find it easier to add plugins and double check everything on localhost.)
- You probably have your xAMP environment set up already. So did I, and therefore all I needed to do was to:
- Set the CLEARDB_DATABASE_URL variable to whatever URI “heroku config | CLEARDB_DATABASE_URL” displays
- Create a symlink to your apache document root: “ln -s /Users/wimagguc/heroku-wordpress-folder/ /var/www/heroku-wordpress-test”
- The best practice is to keep dynamic file content off from Heroku: in case you have multiple instances running, files uploaded to one dyno might be missing from other ones. Keeping all uploaded files on Amazon S3 is one way to solve this problem.
- Go to amazonaws.com and register for Simple Storage Service (now there is a free usage tier for the first year!)
- On the S3 console, create a bucket for your blog
- Get the login credentials from Amazon
- Install this great S3 for WordPress plugin and set it up to use with your bucket