Yet another day trying to write some blog post and I’m not searching for the easy ways surely. Migrating my websites to a single platform was for a long time on my mind – especially this one which I started on Hugo but wasn’t happy with its mediocre look. Of course, I was happy with the “raw” way of doing things – generating blog posts from org-mode within emacs, all with a single keystroke, no mouse..

No, seriously, I think those tools are great. Unless you show them to public – they are for home-use, to be used in a dark-dark closet.. with the lights off.. with the tears in your eyes.. touch-typing.. Ok, nevermind, having such emacs-constant-configuration-mindset, I could not resist installing wordpress from scratch and touching it from the inside, before switching to it.

Not just from scratch – basically no using anything pre-configured, even pre-configured dependencies. Thats what I mean – https://wordpress.org/documentation/article/before-you-install/. If it says mariadb and php in requriements, thats what I do – go and download mariadb and php, no preliminary configurations whatsoever.

As I want to keep my system clean I will do it in docker, using plain alpine base image. Of course, I could use already available mariadb or wordpress images and create pretty easily docker-compose configuration – but thats not me.

https://github.com/thatwist/wordpress-docker-from-scratch

Link to code

I havn’t been using cnf mariadb configuration file, just to keep it simple – only mariadbd minimally required command line options:

mysqld_safe --datadir=/var/lib/mysql/ --log-error=/var/log/mysql/error.log --nowatch \
     --bind-address 0.0.0.0 --skip_networking=0

There was some struggle with log files and making logs appear in docker-compose log output – seems like docker lacks a little bit support for directing log outputs and dealing with background-foreground execution of ENTRYPOINT. But that is solvable with simple bash, of course.

Another story is graceful mariadbd shutdown – docker-compose sends SIGTERM signal to process and waits for some time until simply killing it. We can intercept this and handle using trap:

#Define cleanup procedure
cleanup() {
    echo "Container stopped, performing cleanup..."
    mysqladmin shutdown
}

#Trap SIGTERM
trap 'cleanup' SIGTERM

echo "mysqld is running"
tail -f /var/log/mysql/error.log &

#Wait
wait $!

To make things even more separated, I have put nginx and php into separate services which look into the same folder with wordpress unpacked. At first I thought I could make nginx not accessing wordpress at all but in a current nginx configuration it didn’t like the home / empty address.

Going to the very bottom of things when trying new technology allows to learn and revisit so many things – even such a simple task like WordPress installation.