Skip to content

Instantly share code, notes, and snippets.

@Epigene
Last active April 18, 2019 15:14
Show Gist options
  • Save Epigene/6b1defa2cb1d0f82bd88a478d14898da to your computer and use it in GitHub Desktop.
Save Epigene/6b1defa2cb1d0f82bd88a478d14898da to your computer and use it in GitHub Desktop.
Deploy Wordpress to a Digital Ocean dokku v0.5.6, 2016-05-02

Inspired by jubalm's version

Index

Local

Prepare WP project for running on Dokku

make /composer.json

{
    "scripts": {
        "post-install-cmd": [
            "chmod -R 777 wp-content"
        ]
    },
    "extra": {
        "heroku": {
            "newrelic": "false",
            "nginx-includes": ["nginx.conf"]
        }
    }
}

What to do with composer

Do not bother with composer, do not make composer.lock, only make composer.json in app root with suggested contents.

Make a nginx.conf

# in /nginx.conf

index index.php;

location ~ /\. {
    deny all;
}

location / {
    try_files $uri $uri/ /index.php?$args;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
  access_log off; log_not_found off; expires max;
}

#OPTIONAL block below
client_max_body_size 100M;

#jetpack connection
fastcgi_buffers 8 32k;
fastcgi_buffer_size 64k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;

# enable gzip compression
gzip on;
# Minimum file size in bytes (really small files aren’t worth compressing)
gzip_min_length 1000;
# Compression level, 1-9
gzip_comp_level 2;
gzip_buffers 4 32k;
gzip_types text/plain application/javascript text/xml text/css image/svg+xml;
# Insert `Vary: Accept-Encoding` header, as specified in HTTP1.1 protocol
gzip_vary on;

Make a Procfile

# in /Procfile

web: vendor/bin/heroku-php-nginx -C nginx.conf

modify wp-config

Linking dokku app to db will set an envrionmental variable DATABASE_URL to something like mysql://mariadb:2c82a31766b3bdcd@dokku-mariadb-blog:3306/blog
Use this single variable to set wp config.

Try a wp-config.php with this content (change the secret phrases a bit)

<?php
$url = parse_url(getenv('DATABASE_URL'));

define('DB_NAME', str_replace('/','',$url['path']));
define('DB_USER', $url['user']);
define('DB_PASSWORD', $url['pass']);
define('DB_HOST', $url['host'].":".$url['port']);

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

define('DB_COLLATE', '');

define('AUTH_KEY',         'c8M/}-ZU+GFsTQ])/Cb-+xV=3n#$}*v{y^t|m-zno?xSiiQjk:+u|~1{,m-;~4d-');
define('SECURE_AUTH_KEY',  'cyjMEY.L%O`LA^1o>?P_~qSdmZ_c@$O|``($*C~!2h`iG|]~QQKZkC,vt|3ofV]r');
define('LOGGED_IN_KEY',    'g|-qy;K!+W|S*5`rrhnq%J(yD)U`)wST63Dkz+&l-Uszx:;hDygnN.&`~ZR#>MM[');
define('NONCE_KEY',        'SlQ)4*Put{<(c],Z?;oWPbMC0Q9-I) ukHi]$)XO?/a1&J*sL./Xo3u#u%I:kVhn');
define('AUTH_SALT',        'lr@,Z&Y`4ykd{%b$*ds5w/+j64 mVQ2NS!`07om0Tiy,lT5-`Wp<~LLd$kH?aF[?');
define('SECURE_AUTH_SALT', '|+rEr-hi,E39o;*x^I:sdw;A<!@mm ]G3gWw+J#kw,vcEH<! y7K(Brw}<iJUu5H');
define('LOGGED_IN_SALT',   '[kq(@!>>Eg1 ~~IwLzkh,!6N-8Jc<s9<eq?.9Tizx/BOqYx%7tA=pi3GS8|~4=$`');
define('NONCE_SALT',       ' 5@t( 25Op#DfC1c9ilvgj T$Vn@EfX;f<7ov;nNJ %T.X+Vl#s|0t(ODemft1>U');

$table_prefix  = 'wp_';

define('WP_DEBUG', false);

if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');

require_once(ABSPATH . 'wp-settings.php');

Droplet Side

Setup a droplet

See shared dokku workflow

Prepare Dokku

dokku plugin:install https://github.com/dokku/dokku-mariadb.git mariadb

Check out test blog app

git clone https://github.com/CreativeGS/creative_wordpress_template.git blog

Prepare Dokku app

1. Initialize app

dokku apps:create blog

2. Set up the blog database

dokku mariadb:create blog
dokku mariadb:link blog blog

Deploying

1. Make sure your ssh key is on server's dokku user

cat ~/.ssh/id_rsa.pub | ssh root@<IP> "sudo sshcommand acl-add dokku <key name>"
# e.g.
cat ~/.ssh/id_rsa.pub | ssh [email protected] "sudo sshcommand acl-add dokku deployer"

2. Locally add remote and deploy

git remote rm dokku
git remote add dokku [email protected]:blog
# or via IP
git remote add dokku [email protected]:blog
git push dokku dokku:master

Post-deploy

1. Set persistence environmental variables

# 0. remove wrong existing options
dokku docker-options blog
dokku docker-options:remove blog deploy,run "-v /home/dokku/persistance/blog/wp-content:/app/wp-content"
# 1. make a persistance folder in dokku root
mkdir /home/dokku/persistance/blog
# 2. define the linking option, both on deploy and run phases
dokku docker-options:add blog deploy,run "-v /home/dokku/persistance/blog/uploads:/app/wp-content/uploads"

2. Set domains in VHOST

in /home/dokku/blog/VHOST

blog.blogs2.creative.gs
blog.example.com

Install NewRelic

PHP NewRelic comes as a debian package. Use dokku-apt plugin to manage those.

1. Download the three latest packages for from NewRelic repo.
newrelic-daemon, newrelic-php5-common, and newrelic-php5
https://download.newrelic.com/debian/dists/newrelic/non-free/binary-amd64/

See the installation documentation if links are broken.

2. Place the packages in project /dpkg-packages

You must also rename the packages, so they are executed in specific order:

  1. newrelic-php-common
  2. newrelic-daemon
  3. newrelic-php
3. Make /apt-debconf file

This file controlls the configuration of package installation.
It must contain two lines, one for configuring the app name, the other for the license.

newrelic-php5 newrelic-php5/application-name string "<app name>"
newrelic-php5 newrelic-php5/license-key string "<newrelic license key>"

e.g.
newrelic-php5 newrelic-php5/application-name string "test blog"
newrelic-php5 newrelic-php5/license-key string "1ae8e02b0d25axce858201g14f6946fe6d97ba1f"
4. Install the dokku-apt plugin
dokku plugin:install https://github.com/F4-Group/dokku-apt
5. Deploy and Debug

While deploying, dokku-apt should be verbose about the packages it installed.
After deploy enter the container

# get containers by running `sudo docker ps`
sudo docker run -it dokku/wp:latest /bin/bash

And run

$ /etc/init.d/newrelic-daemon start
#=> New Relic Daemon: newrelic-daemon already running

NB, unfortunately neither ps aux or other process debuggers will show the daemon as running.

Troubleshooting

remote: gzip: stdin: not in gzip format

PHP Buildpack issue, downgrade to stable version Unconfirmed, v102 also fixes

# per app, recommended
dokku config:set <app> BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php.git#v95

# global, may break things
dokku config:set --global BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php.git#v95

Debug PHP environment

Replace root index.php with

<?php
phpinfo();
?>

Upload size

Dokku-side (nginx 413 entity too large error)

Consult nginx templating docs

Create a nginx.conf.sigil file in app root for dokku to pick up when building container nginx
Populate the file with basic template
Add a client_max_body_size 100M; line in the server block or top level if it is absent

Appside

Use .user.ini as suggested in heroku docs
Root level .user.ini will set "local" value for all app

extension=gd.so
memory_limit=256M

Uninstalling a plugin

Delete the plugin from /var/lib/dokku/plugins.
Consult this thread

Increasing MySQL/MariaDB/InnoDB memory

Consult documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment