Deploying WordPress in Heroku

Download latest version of wordpress.

$ wget
$ unzip
$ mv wordpress mywebsite # optional if you want to rename the folder.

Create “Procfile” and put this following line.

web: vendor/bin/heroku-php-apache2

Create “composer.json and put this following line.

{"require": {"php": "5.6.27"}}

Configure the wordpress by creating “wp-config.php”. WordPress already had the template, so you just need to rename it.

mv wp-config-sample.php wp-config.php

Edit “wp-config.php” and replace following line.

// ** MySQL settings - You can get this info from your web host ** //
$url = parse_url(getenv('DATABASE_URL') ? getenv('DATABASE_URL') : getenv('CLEARDB_DATABASE_URL'));

/** The name of the database for WordPress */
define('DB_NAME', trim($url['path'], '/'));

/** MySQL database username */
define('DB_USER', $url['user']);

/** MySQL database password */
define('DB_PASSWORD', $url['pass']);

/** MySQL hostname */
define('DB_HOST', $url['host']);

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('AUTH_KEY',         getenv('AUTH_KEY'));
define('SECURE_AUTH_KEY',  getenv('SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY',    getenv('LOGGED_IN_KEY'));
define('NONCE_KEY',        getenv('NONCE_KEY'));
define('AUTH_SALT',        getenv('AUTH_SALT'));
define('LOGGED_IN_SALT',   getenv('LOGGED_IN_SALT'));
define('NONCE_SALT',       getenv('NONCE_SALT'));

Now is the deployment process, ensure you have installed heroku toolbelt and already sign in on it.

$ git init
$ git add -A
$ git commit -m "basic setup wordpress heroku"
$ heroku create
$ heroku addons:add cleardb

After that, put following environment variables with new values. You can generate those in here.

heroku config:set AUTH_KEY=''
heroku config:set SECURE_AUTH_KEY=''
heroku config:set LOGGED_IN_KEY=''
heroku config:set NONCE_KEY=''
heroku config:set AUTH_SALT=''
heroku config:set SECURE_AUTH_SALT=''
heroku config:set LOGGED_IN_SALT=''
heroku config:set NONCE_SALT=''

Now we need download all the dependencies, ensure you have composer installed. If you are not, you can install following this.

$ curl -sS | php
$ php composer.phar install

Last step is deployment.

$ git add composer.lock
$ git commit -m "final step"
$ git push heroku master


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.