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
Open the project in your favorite editor. Right now mine is Sublime text which I have symlinked to the word sublime in Terminal
$ sublime .
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"
Now I like to do Email Setup.
Deploy to Heroku
$ gphp (git push heroku production:master)
After deployment WordPress has a few more steps to setup and thats it!
Media Uploads
CAVEAT: Currently the plugin used to save images to Amazon S3 does not generate thumbnails Github Issue here is an alternative option I have not tried yet: http://wordpress.org/plugins/tantan-s3-cloudfront/
WP Read-Only plugin is included in the repository allowing the use of S3 for media uploads.
- Activate the plugin under 'Plugins', if not already activated.
- 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' ););
Add your Mandrill info to your heroku config
$ heroku config:add MANDRILL_USERNAME=username MANDRILL_API_KEY=apikey
Usage
- Because a file cannot be written to Heroku's file system, updating and installing plugins or themes should be done locally and then pushed to Heroku.
Setting up a local environment
Mac OS X
- To run WordPress locally on Mac OS X try MAMP.
- This template requires Postgres as the local database so install Postgres.app
- Open psql, from the menubar elephant icon, and run...
CREATE DATABASE wordpress;
CREATE USER wordpress WITH PASSWORD 'wordpress';
GRANT ALL PRIVILEGES ON DATABASE wordpress to wordpress;
- Open /Applications/MAMP/Library/bin/envvars and add
export DATABASE_URL="postgres://wordpress:wordpress@localhost:5432/wordpress"
- Start MAMP and open http://localhost/wp-admin/ in a browser.
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.