Worpdress on Dokku

I recently found Dokku when digging around the interwebs and decided it would be a really nice way to manage my sites/apps instead of installing environments willy-nilly on a server. So I set out to figure out how to get a basic blog up and running under Dokku. Turns out getting WordPress running isn’t terribly difficult. So here are the steps to follow to get things working:

  1. Install Dokku (obvious, but just in case you were wondering)
  2. Set up your local app
  3. Set up the remote app
    1. Set up databases
    2. Set up persistent storage
  4. Profit! (Sorry I had to)

  5. Install Dokku

I could walk you through all of the install steps, but really you should just go to Dokku’s documentation and follow the instructions there.

Note: I will admit that I cheated a bit here, and just used Digital Ocean’s prebuilt Dokku image. If you choose to go down that route, and use the smallest size of DO server you’ll want to take a look at how to add swap space (or [here] (https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04)) to your server.


2. Set up your local app

This is pretty boring, go and download wordpress to your machine. Pick somewhere one your machine to buld this project, I use ~/projects/blog. Within that folder, you will want to unpack the archive you downloaded before to a new directory, something like public. Install composer if you haven’t already, take a look at the composer documentation for that. Add a file in your project directory with the name composer.json and add the following as content (replacing the values in []):

    "name": "[your_blog_name]",
    "description": "[Some description]",
    "authors": [
            "name": "[Your Name]",
    "minimum-stability": "stable",
    "require": {
        "php": ">=5.6"

Open up a terminal and navigate to your project directory and run composer install to create the lock file.

3. Set up the remote app

Now on your remote server ssh in and create the app in dokku – dokku apps:create [app-name or domain]. Next we need to handle the database and persistent storage. First, let me set up the database. WordPress works most easily with mysql/mariadb so I need to install the dokku plugin for one of those two. I prefer mariadb as I like to avoid Oracle wherever possible, but use what you prefer. To install the mariadb plugin just run sudo dokku plugin:install https://github.com/dokku/dokku-mariadb.git mariadb and it will do all of the heavy lifting for you. Now that the plugin is installed, we need to create and link the database. First run dokku mariadb:create [db-name] to create the database container, then run dokku mariadb:link [db-name] [app-name] to add an environment variable to the remote app and allow access. You might want to copy the url that is shown as you will need it in the next section.

4. Update the local app config

Jump into wp-config-sample.php to make the needed changes. First things first look at the DSN that we grabbed before (that’s the connection URL that looks something like mysql://mariadb:[password@[hostname]:3306/[database]). You need the user, password, host and database name to proceed. Once you have those look for define(DB_NAME, ''), define(DB_USER, ''), define(DB_PASSWORD, '') and define(DB_HOST, '') and enter the values from the DSN where appropriate. The only other thing we should need to do in the config before saving it is add some salts. Go to WordPress secret-key service and replace the values in your config file with the ones generated by that webpage.

5. Add a persistent volume

Back on the server we need to create a persistent volume to store file uploads and any tweaks we make to the theme or plugins. So run dokku storage:mount [app-name] [host-path]:/app/public/wp-content which will create a permanent mount from the host to the container. For the host path the documentation recommends using /var/lib/dokku/data/storage, but to allow for multiple apps I append the app name to the end – /var/lib/dokku/data/storage/[app-name].

6. Commit and run

If you haven’t done so already hop into a terminal on your local machine and initialize a git repository with git init. Then you need to add the dokku remote with git remote add dokku dokku@[your-ip-or-hostname]:[app-name]. Commit your changes and the push to dokku with git push dokku master. If everything is hunky dory (and I haven’t accidentally left out a step…) you should see a bunch of output from dokku on your server and once that’s done your workdpress install will be up. Once that is done hit [app-name].hostname.tldd to start the actual WordPress install.

I hope this helps someone (or future me) to get started with dokku.  

Also read...

Leave a Reply

Your email address will not be published. Required fields are marked *