Installing WordPress on Dokku

To get WP up and running you have to prepare several things. This guide is based on a Dokku installation on a DigitalOcean Dropplet; for me the most convenient way to get a Dokku platform running.

Prepare your dokku environment

To make sure everything is on place, you should prepare your dokku environment.

1. Add your app

Create a app with the  dokku apps:create <appname> where appname is the sub domain of your dokku server.

2. Add a Database

I’ll use the official mariadb plugin for firing up a mysql database.

First add a new database by executing the following command  dokku mariadb:create .

Choose whatever you want for the databasename.

After firing the command, you should see a output like this:

Please note the line

  DSN: mysql://mariadb:2995cee44058d534@dokku-mariadb-my-wp-database:3306/my_wp_database 

we will need this information later to configure the WordPress database!

Now connect your database to your app. This step makes sure your app has access to the db.

dokku mariadb:link my_wp_database yourappname

3. Prepare the app configuration

Now we have to set some environment variables and docker options to make sure that WordPress is able to connect to the database, to crypt some cookies and to persist your data (uploads, themes, plugins). This is a very important step to make sure your data will be in place even after a restart of the container or the server.

Set the config

First start with the database configuration. You remember the DSN you got after you created the Database?

DSN: mysql://mariadb:2995cee44058d534@dokku-mariadb-my-wp-database:3306/my_wp_database

Lets split the string into some useable variables and set these for the app. Please execute the following commands (keep in mind that your appname and database credentials are different, so make sure you replace them):

Next are the salt values for several security features of WordPress

Do a  dokku config . This gives you a list of all environment variables set for your app

Everything in place? Then move on 🙂

Configure the docker-options

This Step is very important to preserve uploads and downloaded themes and plugins. If you miss these steps, your files will we gone after a restart of the container.

Just create a directory on your dokku host. For my example, i created the directory /opt/wordpress/.

Then link the directory to your container:

dokku docker-options:add yourappname deploy,run "-v /opt/wordpress:/app/wp-content"

Thats all, the environment is prepared now. Let’s configure and deploy WordPress 🙂

Prepare WordPress

Just clone the current WordPress repository from Github and add a deployment branch:

 

First add a file called composer.json to your repository. This will make sure that the correct version of php will be used and also install some basic libraries like gd and curl.

 

Next add a file called nginx_app.conf. This configures the nginx service for your subdomain/app.

 

I also added a file called custom_php.ini where you can set several php options for your deployment.

 

Now add a file named Procfile. This will ensure dokku is loading your configuration.

Finally, copy the file wp-config.php.sample to wp-config.php and modify some variables:

If everything is done, commit the files and changes to our branch

 

Deploy your app

Now we have to add your dokku server as a git remote (remember to change the dokku server and hostname)

git remote add dokku dokku@myserver.com:myhostname

And now, DEPLOY

git push dokku deployment:master