So, last week, Heroku announced that they are now officially supporting PHP on their platform. Now, they’ve actually been “unofficially” supporting PHP for well over a year now, so I was super happy to see that they have now officially given it the nod (especially since I’ve been running several production applications on the platform for quite some time now).
Ok, so, here’s what you do to get WordPress running on Heroku:
- Fork my repo: https://github.com/sinned/wordpress-heroku
- Clone your forked repo:
git clone [email protected]:sinned/wordpress-heroku.git awesome cd awesome
- Create the heroku instance
- Add ClearDB
heroku addons:add cleardb:ignite
- Push to heroku
git push heroku master
- Go to your heroku app in a browser
- Follow the instructions to set up your WordPress.
- Log in to WordPress and then set up the S3 and Mandrill/Mailgun plugins (because of reasons we explain below)
For those of you that are familiar with running WordPress on your own server, deploying it to Heroku should be pretty easy to understand, with a few main things to remember:
- My github build is meant for you to be able to run a local version of WordPress and then push it to production. I find this handy for development — that said, if you are only going to push to Heroku once and then never redeploy, then I urge you to check out Mark Chung’s WordPress Buildpack.
- The file system on Heroku is ephemeral, meaning that each time you deploy to it, anything not in the github repository is blown away. Most notably, this means that if you upgrade WordPress through the Admin UI, unless you upgrade your local repo, if you redeploy, bad things will happen. Additionally, your beloved /wp-content/uploads/ directory will also disappear.
- So — to combat the file system issue, I’ve included an S3 plugin — that way, any media you upload is stored at S3 instead of your ephemeral Heroku file system. And, it’ll be faster that way anyway — S3 is much better at serving static content than Heroku dynos are. The WordPress Read Only plugin is another one to look at for this purpose.
- The php ‘mail’ function on Heroku does not work — so, in order for the emails to work, you need to use something like wpmandrill or mailgun (which I have included)
Mark Chung’s wordpress-on-heroku build is really fast, but mine is slightly different in that it allows you to run a local version of WordPress (with the MySQL credentials wordpress-heroku/wordpress-heroku). That said, I do have some things that I need to address:
- The security salts are still stored in wp-config.php — I should probably move these to a Heroku setting of some sort for better security.
- The AWS credentials are stored in the DB, so if anyone gets access to your database, that could be bad. Move these to a Heroku setting as well.
Anyway.. hopefully you find this post useful. Let me know if you have any questions or comments.