WordPress configurations for Heroku

Starting…

Download the last version of wordpress, then create a directory called “wordpress” (or anything you want else to call it) and extract the content of the zip to the directory.

WordPress Configuration

Jump to your directory and create the Procfile with this line

1
web: vendor/bin/heroku-php-apache2 /

Add a file for composer, named composer.json

1
2
3
4
5
6
7
{
  "name" : "Wordpress",
  "require" : {
    "php" : ">=5.3.3",
    "ext-mbstring" : "*"
  }
}

Edit the wp-config.php file and replace the first lines with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$db = parse_url(getenv('CLEARDB_DATABASE_URL'));

define('DB_NAME', str_replace('/', '', $db['path']));
define('DB_USER', $db['user']);
define('DB_PASSWORD', $db['pass']);
define('DB_HOST', $db['host']);

define('AUTH_KEY',         '{%AUTH_KEY%}');
define('SECURE_AUTH_KEY',  '{%SECURE_AUTH_KEY%}');
define('LOGGED_IN_KEY',    '{%LOGGED_IN_KEY%}');
define('NONCE_KEY',        '{%NONCE_KEY%}');
define('AUTH_SALT',        '{%AUTH_SALT%}');
define('SECURE_AUTH_SALT', '{%SECURE_AUTH_SALT%}');
define('LOGGED_IN_SALT',   '{%LOGGED_IN_SALT%}');
define('NONCE_SALT',       '{%NONCE_SALT%}');

Git repository

1
2
3
4
5
6
7
8
9
10
11
$ git init
Initialized empty Git repository
$ echo "/wp-content/plugins/" >> .gitignore
$ echo "/wp-content/themes/" >> .gitignore
$ git add .
$ git commit -am 'First commit'
[master (root-commit) 83b5792] First commit
 1014 files changed, 384288 insertions(+)
 create mode 100644 .gitignore
....
 create mode 100644 xmlrpc.php

Configure Heroku

Create an App with heroku toolbelt setting up the app name my-wordpress-app and the region eu

1
$ heroku apps:create --region eu my-wordpress-app

Database

Creating the database, this will create a free cleardb on heroku and add the system variable CLEARDB_DATABASE_URL:

1
2
3
4
5
$ heroku addons:create cleardb:ignite
Creating giving-gently-8505... done, (free)
Adding giving-gently-8505 to my-wordpress-app... done
Setting CLEARDB_DATABASE_URL and restarting my-wordpress-app... done, v3
Use <code>heroku addons:docs cleardb</code> to view documentation.

The Deploy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
git push heroku master
Counting objects: 1101, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1079/1079), done.
Writing objects: 100% (1101/1101), 4.61 MiB | 282.00 KiB/s, done.
Total 1101 (delta 63), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Resolved composer.json requirement for PHP to version 5.6.11.
remote: -----> Installing system packages...
remote:        - PHP 5.6.11
remote:        - Apache 2.4.10
remote:        - Nginx 1.6.0
remote: -----> Installing PHP extensions...
remote:        - mbstring (composer.json; bundled)
remote:        - zend-opcache (automatic; bundled)
remote: -----> Installing dependencies...
remote:        Composer version 1.0.0-alpha10 2015-04-14 21:18:51
remote:        Loading composer repositories with package information
remote:        Installing dependencies
remote:        Nothing to install or update
remote:        Writing lock file
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 77.0MB
remote: -----> Launching... done, v4
remote:        https://my-wordpress-app.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/my-wordpress-app.git
   83b2946..4274dc2  master -> master

Finally, load your website and finish the wordpress configurations.
Screen Shot 2015-07-30 at 16.43.29

I hope it was usefull.

Leave a Comment