DEV Community

Jasmine Tracey
Jasmine Tracey

Posted on • Edited on • Originally published at jasminetracey.com

How to set up your wordpress site on dokku

This post will cover everything you need to know about getting WordPress deployed to your dokku server from start to finish.

I already have a dokku server setup on digital ocean.
If you haven't done so as yet you can create an account and get 100 credits [Free 100 credit (https://m.do.co/c/04ef1769fce8)
After that follow the instructions on the dokku documenation to get your server up and running DigitalOcean Droplet Installation Notes

Let us begin, to get the most out of this tutorial follow along and comment below if there are any issues with the steps.

Installing the MariaDB plugin on dokku, creating a database, and linking it to our app

In your dokku terminal run the following command to create your app. I will be using blogger as my app name feel free to use another name.

dokku apps:create blogger
Enter fullscreen mode Exit fullscreen mode

If you run dokku apps:list you should see your newly created application.

Now will install the mariab plugin, create a database and link it to our app so that it has access to it

# Install app
sudo dokku plugin:install https://github.com/dokku/dokku-mariadb.git mariadb

# Create database
dokku mariadb:create bloggerdb

# Link database to app
dokku mariadb:link bloggerdb blogger
Enter fullscreen mode Exit fullscreen mode

Creating a local wordpress instance and pushing it to dokku

On your local machine clone the wordpress github project

# Download and unzip wordpress files
curl -LO https://wordpress.org/latest.zip
unzip latest.zip

# Change directory to downloaded project
cd wordpress

# Download wordpress gitignore file
curl https://raw.githubusercontent.com/github/gitignore/master/WordPress.gitignore > .gitignore

# Initialize repository and make initial commit 
git init
git add .
git commit -m "Initial commit of wordpress files"

# Open folder in your code editor for this tutorial i'll be using visual studio code
code .
Enter fullscreen mode Exit fullscreen mode

We are going to update the values of our config file so it knows to look for the dokku environment variables. First copy wp-config-sample.php to wp-config.php. Then update the following sections

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

$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);

/** The name of the database for WordPress */
define( 'DB_NAME', $database );

/** MySQL database username */
define( 'DB_USER', $username );

/** MySQL database password */
define( 'DB_PASSWORD', $password );

/** MySQL hostname */
define( 'DB_HOST', $host );
Enter fullscreen mode Exit fullscreen mode

We also want to change authentication keys and salts so go to https://api.wordpress.org/secret-key/1.1/salt/ copy and paste the generated salts in the wp-config.php file

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );
Enter fullscreen mode Exit fullscreen mode

We also need to create a custom_php.ini file to improve some settings

upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 60
memory_limit = 512M
Enter fullscreen mode Exit fullscreen mode

Now we need to tell dokku to use those settings when running the project to do that we will use a Procfile in the root of the project

web: vendor/bin/heroku-php-nginx -i custom_php.ini
Enter fullscreen mode Exit fullscreen mode

Now we will commit and push our changes to our dokku server

# commit changes
git add .
git commit -m "updated config to work with dokku url"

# Add the dokku url to the downloaded project
# If your server is dokkuserver.com and your blog is called blogger this would be:
git remote add dokku dokku@dokkuserver.com:blogger

# push changes
git push dokku master
Enter fullscreen mode Exit fullscreen mode

Setting up application storage on dokku server

# Create the folders (might require sudo)
mkdir -p /var/lib/dokku/data/storage/blogger/plugins
mkdir -p /var/lib/dokku/data/storage/blogger/themes
mkdir -p /var/lib/dokku/data/storage/blogger/uploads

# Change the permission (might require sudo)
chown 32767:32767 /var/lib/dokku/data/storage/blogger/plugins
chown 32767:32767 /var/lib/dokku/data/storage/blogger/themes
chown 32767:32767 /var/lib/dokku/data/storage/blogger/uploads

# Mount the storage to the container
dokku storage:mount blogger /var/lib/dokku/data/storage/blogger/plugins:/app/wp-content/plugins
dokku storage:mount blogger /var/lib/dokku/data/storage/blogger/themes:/app/wp-content/themes
dokku storage:mount blogger /var/lib/dokku/data/storage/blogger/uploads:/app/wp-content/uploads
Enter fullscreen mode Exit fullscreen mode

The default upload limit for nginx is 2mb let us update the limit to 100mb. Sudo may be required to run these commands

mkdir /home/dokku/blogger/nginx.conf.d/
echo 'client_max_body_size 100M;' > /home/dokku/blogger/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/blogger/nginx.conf.d
service nginx reload
Enter fullscreen mode Exit fullscreen mode

We are almost finish. To ensure we have a secure site, we will add https using lets encrypt

# Install plugin
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git

# Set the global email
dokku config:set --global DOKKU_LETSENCRYPT_EMAIL=your@email.tld

# Setup cronjob to auto-renew certificates when they expire
dokku letsencrypt:cron-job --add

# Add https to site
dokku letsencrypt:enable blogger
Enter fullscreen mode Exit fullscreen mode

Go to your url application url in your browser you should see the installation page of your wordpress site. Thank you for following along

Resources

Top comments (12)

Collapse
 
dvjones89 profile image
Dave Jones

Thanks for this fantastic write-up, Jasmine, I had a Wordpress installation running in Dokku within 10 minutes flat 🙌🏼

One tiny correction, for the benefit of future readers, the final command where we're enabling letsencrypt for the blogger application should include the word "enable"

dokku letsencrypt:enable blogger
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leandertolksdorf profile image
Leander Tolksdorf

I get this error when trying to push to the dokku host:

-----> Unable to select a buildpack
remote: 2022/01/03 10:53:44 exit status 1
remote: 2022/01/03 10:53:44 exit status 1
To myhost.com:app
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'myhost.com:app'
Enter fullscreen mode Exit fullscreen mode

How can I fix this?

Collapse
 
mahedicse profile image
Md Mahedi Hasan

I'm getting this error: "The theme directory "twentytwentythree" does not exist.
Error: The themes directory is either empty or does not exist. Please check your installation." and unable to install any theme and plugins

Collapse
 
eventyret profile image
Simen Daehlin

Amazing guide thank you! It seems that after applying Letsencrypt all CSS will be broken and so will all js etc. Any good solution @jasminetracey

Collapse
 
jasminetracey profile image
Jasmine Tracey

From your admin panel under settings you can change your WordPress Address (URL) and your Site Address (URL) to the https version.

Collapse
 
vomba profile image
vomba

Hey, doing that makes the website inaccessible, browser says too many redirects.

Thread Thread
 
jasminetracey profile image
Jasmine Tracey • Edited

This article should help

wpbeginner.com/wp-tutorials/how-to...

Collapse
 
bi_khadija profile image
Bhamiji Khadija Mahanga

Can you use wordpress docker image on dokku?

Collapse
 
jasminetracey profile image
Jasmine Tracey

yes

Collapse
 
joshco profile image
Josh

I am getting 404's for all pages except the main page. wp-admin works.
Is there something I need to do for URL rewrites instead of .htaccess ?

Collapse
 
jasminetracey profile image
Jasmine Tracey

You can try adding options +FollowSymLinks to your .htaccess file

Collapse
 
joshco profile image
Josh • Edited

I changerd my Procfile to use apache rather than nginx, and it picked up my standard wordpress .htaccess file and it works without 404s

Procfile
web: vendor/heroku/heroku-buildpack-php/bin/heroku-php-apache2

I found this voodoo here: github.com/dokku/dokku/issues/824
It looks like it may be related to a newer or older version of buildstep.