Categories

[Tutorial] Deploying wordpress with Dokku

Few days ago, I tried deploying WordPress using dokku with digitalocean’s VPS, but I run into several issues, the biggest one of them was getting WordPress permalinks to work properly.

Since dokku uses an advanced php buildpack (can be found here), we will try to leverage its settings to get our a WordPress blog deployed. In fact this blog was deployed using the same steps bellow.

So let’s get started.

Clone wordpress locally

We’ll start by cloning WordPress locally:

git clone https://github.com/WordPress/WordPress.git blog

Create an empty compose.lock

The reason we do that is to force the buildpack to detect our wordpress as a composer app. We will see later how to use composer.json to configure both nginx and newrelic and even set permissions for our wp-content folder.

create a composer.lock in the root folder with an empty json object:

{}

Create a composer.json

This is the most important step in this tutorial, create a composer.json with the following content, in our case this file will be used by the buildpack to setup our environment:

Create mariadb container (dokku plugin)

Then create a database (the name must match your blog name, otherwise your blog container and database container won’t be linked)

dokku mariadb:create blog

Adding persistent volumes for plugins and themes

To be able to use volumes with dokku, we need to leverage another plugin call docker-options. Everything you do will be done once only, redeploying your application won’t change anything except wordpress’ code base.

Oops nothing shows up !!!

Since we mapped wp-content as a volume in the host, it’s content is rewritten when we deploy for the first time.

What you need to do is to go to your dashboard: http://www.blog.com/wp-login.phpand install your first theme.

if you run into permission problems ( failure in installing plugins or themes ), either attach to your dokku container, and run this inside: chmod -R 777 /app/wp-content, or you can browse to you persistent volume, remember that we use /opt/blog/, do a chmod -R 777 /opt/blog Everything should work properly now.

Optional plugins for nginx caching and performance boosting

Since we are using nginx, you can enhance the performance of your blog using a simple plugin called nginx-helper.

Just install it, no configuration needed.

That’s it, I hope this saves someone some time. I plan to setup a repo in github with all this configuration, stay tuned.

Hi There Pedro, what you should do is to create persistent volume for the uploads folder, the same way we did for plugins and themes folders, I just updated the post, see ‘Adding persistent volumes for plugins and themes’ section.

Excellent tutorial, however, there is one issue regarding omission of information that kind of screwed my over and took a long while to figure out. Right here:

“Then create a database (the name must match you blog name, otherwise your blog container and database container won’t be linked)”

This is not clear. Nowhere in the article did you previously mention the importance of the “blog container” name, which is incorrect, because not everyone will use the term “blog.” They may use “store” or “splash” or “community.”

I would suggest appending some helpful info regarding this configuration higher up in the article, so that people are aware of the *context* of their actions when determining slugs. As of now, we (visitors) just follow the instructions somewhat blindly, and in this circumstance we have no idea what the consequences of our actions are when we don’t use the slug name “blog,” which is a perfectly acceptable diversion.

Maybe something like… “And now you will decide on your *CONTAINER NAME,* choose a name and remember it, because you will need it again when we create the database. I used ‘blog,’ but you are welcome to use whatever is relevant to your project.”

Is blog the git name?
The host name?
The container name?
How do I obtain the container name? … I tried “docker ps –no-trunc” but that gives a “name” that is randomized similar to heroku hostnames.

Because of this mix-up, I have no database connection, and after repeating the mariadb step 3-4 times hoping I get name correct, I have lost patience.

Shed some light? Clarify terminology? Or maybe I’ve read the article so many times I’m just not seeing it.

Hey Sean, first of all thank you for your comment. I really appreciate the time you took to write this.

As I can see, you are familiar with Docker, but not quite with Dokku (Just saying).

As for the application name, it’s what you use when you push your app to the server, I am not talking about the container’s name. As far as I am aware of, dokku does not make use of them at all, plugins do, for linking purposes.

When you first setup your remote repository with git, you do this:git remote add dokku [email protected]:APPNAME
now APPNAME is your application name, use that when you create your mariadb container, I used blog as the APPNAME.

This APPNAME is also what dokku will use as a subdomain for your application (if you are using virtual hosts): APPNAME.domain.com.