Andrew Gertig

Set up Wordpress on Heroku

This is pretty much me summarizing and slightly adapting the Readme from the project by Matt Hoofman mhoofman/wordpress-heroku. Here is my fork of the repo just in case.

If you notice some shortened commands like gp instead of git push it is because I have aliased them in my .bash_profile.

WordPress Heroku

This project is a template for installing and running WordPress on Heroku. The repository comes bundled with PostgreSQL for WordPress and WP Read-Only.

Installation

Clone the repository from Github

$ git clone git://github.com/mhoofman/wordpress-heroku.git wp-appname

With the Heroku gem, create your app

$ cd wp-appname
$ heroku create wp-appname

Add a database to your app

$ heroku addons:add heroku-postgresql:dev

Promote the database (replace COLOR with the color name from the above output)

$ heroku pg:promote HEROKU_POSTGRESQL_COLOR

Create a new branch for any configuration/setup changes needed

$ gcnb production              (git checkout -b production)

Copy the wp-config.php

$ cp wp-config-sample.php wp-config.php

Update unique keys and salts in wp-config.php on lines 48-55. Wordpress can provide random values here.

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Clear .gitignore and commit wp-config.php

$ >.gitignore
$ git add .
$ git commit -m "Initial WordPress commit"

Deploy to Heroku

$ gphp            (git push heroku production:master)

After deployment WordPress has a few more steps to setup and thats it!

Media Uploads

WP Read-Only plugin is included in the repository allowing the use of S3 for media uploads.

  1. Activate the plugin under 'Plugins', if not already activated.
  2. Input your Amazon S3 credentials in 'Settings'->'WPRO Settings'.

Custom Domains

Heroku allows you to add custom domains to your site.

$ heroku domains:add www.example.com
$ heroku domains:add example.com

Setup DNS A records for the following ip addresses to point to your domain, or use proxy.herokuapp.com

75.101.163.44
75.101.145.87
174.129.212.2

In the WordPress Admin Dashboard, go to Settings --> General. Change both urls to match your www url

Email Setup for Mandrill

Browse to wp-includes/pluggable.php then find the line:

 $phpmailer->IsMail();

Comment it out and add the following:

  // Set to use PHP's mail()
  // $phpmailer->IsMail();

  // Over ride and set to use SMTP. Set enviromental variables.
  $phpmailer->IsSMTP();
  $phpmailer->SMTPAuth = true; // enable SMTP authentication
  $phpmailer->Port = 587; //25; // set the SMTP server port

  $phpmailer->Host = 'smtp.mandrillapp.com'; // SMTP server
  $phpmailer->Username = $_ENV["MANDRILL_USERNAME"]; // SMTP server username
  $phpmailer->Password = $_ENV["MANDRILL_API_KEY"]; // SMTP server password

  $phpmailer->From = $bloginfo = get_bloginfo( 'admin_email', 'raw' );
  $phpmailer->FromName = $bloginfo = get_bloginfo( 'name', 'raw' );
  $phpmailer->Sender = $bloginfo = get_bloginfo( 'admin_email', 'raw' );
  //$phpmailer->AddReplyTo($bloginfo = get_bloginfo( 'admin_email', 'raw' );, $bloginfo = get_bloginfo( 'name', 'raw' ););

Usage

Setting up a local environment

Mac OS X

CREATE DATABASE wordpress;
CREATE USER wordpress WITH PASSWORD 'wordpress';
GRANT ALL PRIVILEGES ON DATABASE wordpress to wordpress;

Updating WordPress

Updating your WordPress version is just a matter of merging the updates into the branch created from the installation.

$ git pull # Get the latest

Using the same branch name from our installation:

$ git checkout production
$ git merge master # Merge latest
$ git push heroku production:master

WordPress needs to update the database. After push, navigate to:

http://your-app-url.herokuapp.com/wp-admin

WordPress will prompt for updating the database. After that you'll be good to go.

Setting up two WordPress blogs in under an hour on Heroku

This blog post you are reading right now is a Ruby on Rails site, hosted on Heroku, that I have been working on as a learning experiment and to keep me involved in the Rails world. The posts are written in Markdown and comments are handled by Disqus.

However, I recently came across a post about installing WordPress on Heroku which then lead me to this project on github by Matt Hoofman. I decided to give it a shot and use two domain names I've had laying around for a while as my guinea pigs. Within an hour I had both sites Arduinocasts.com and NormalRunner.com up and working. I was extremely impressed with how easy it was to do on Heroku and think its a great way to try out an idea you might have for a blog without having to setup paid hosting to do so.

Let me know if you've tried this out yourself and what your thoughts are about using Heroku to host a WordPress site.

Twitter42 Youtube42 Google-plus42