New Blog Stuff!

As a first post on my newly updated blog, I figured I’ll explain my setup. After experimenting with Jekyll, Gatsby, and Hugo I realized I didn’t want to learn an entire static site generator system for something so simple. While learning is important (my favorite thing to do, in fact), what mattered more was the TTL (time to live). I needed something that I could work with and quickly get results.

Enter WordPress! According to W3Techs, WordPress accounts for 60% of the market share for content management systems on the web! I’ve used it at work, for clients, and through WordPress.com, where my blog was originally located.

WordPress.com was a bit too restrictive compared to a self-hosted WordPress installation. You can’t add plugins or JavaScript or tweak the theme files and such. For this reason, I started to look into self-hosting a WordPress environment. But then it hit me – why not just export the site and host it for free on GitHub pages?

Since I didn’t need to have a publicly-accessible WordPress site, I decided to use Docker to setup the WordPress and MySQL environment for rapid deployments and easy backup purposes (and because I’m running Windows and didn’t want to pollute it with all the installs for PHP and the like).

My docker-compose.yml file looks like this:

version: '3.6'
services: wordpress: image: wordpress:latest ports: - "80:80" - "443:443" command: 'bash -c /usr/local/bin/apache2-custom.sh' volumes: - ./config/php.conf.uploads.ini:/usr/local/etc/php/conf.d/uploads.ini - ./config/wp-init.sh:/usr/local/bin/apache2-custom.sh - ./wp-app:/var/www/html # Full wordpress project #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development restart: always environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: password depends_on: - db
db: image: mysql:latest command: [ '--default_authentication_plugin=mysql_native_password', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ] volumes: - ./wp-data:/var/lib/mysql restart: always environment: MYSQL_DATABASE: wordpress MYSQL_ROOT_PASSWORD: password

Running docker-compose up -d on this results in WordPress being started using a self-signed SSL cert (see wp-init.sh below) and connects it over to MySQL. All of the data files are mounted as volumes for easy access in Windows/the host environment.

#!/bin/bash
# modified from https://github.com/docker-library/wordpress/issues/46#issuecomment-358266189
apt-get update apt-get install -y --no-install-recommends ssl-cert rm -r /var/lib/apt/lists/*
a2enmod ssl a2ensite default-ssl
# finally execute default command docker-entrypoint.sh apache2-foreground

With that, my local WordPress environment was set up. This admittedly took a few hours across multiple days to get configured just right. I then exported my WordPress.com content and imported it over here. Finally, when I want to update my site here, I simply navigate to the WP Static Site Generator plugin and click export. Voilà!

It works wonderfully well. You get all of the power of WordPress + plugins (SEO, minification, etc.) and all of the speed + security of a static site.