This is part 2 of my brief series of posts on moving my websites onto a server located in my home. Part 1, where I get the idea for the basic plan. (In brief, small-and-quiet Windows machine on my residential ISP. Free Cloudflare Tunnel as the public access point.)
Before I go ahead and make an investment in new hardware, I want to try out hosting a WordPress website on the dev machine in my office. I don’t leave it switched on all the time but it’ll do for practice. My initial thought for running WordPress was to use a Docker container.
Around a year ago, I had written an article bemoaning that WordPress installations weren’t in a neat folder that I could ZIP because the data in the MySQL database needed to be backed up too. I wished that instead of on a database server, that data could be stored inside the same folder as WordPress, perhaps using SQLite.
An anonymous commenter suggested I use WordPress running inside a Docker container. I had used Docker at work so this seemed ideal. All I’d need to do is run the container and I’d have a contained copy of Linux with everything I needed to run WordPress including Apache, PHP, MySQL and all the image processing components.
It would all be so simple. Docker’s own page for WordPress said it all.
Type in a three-word command and it would all install itself? That’s great!
I was very quickly informed this would not be the case. Once its installed into a running container, the package puts you through the setup process. One of the questions I was asked was “Where’s the database server?”
The answer “localhost” was already filled in. For a moment I had hoped that I only needed to accept that default answer because it was only asking in case I wanted to a different database server. Alas, no, There was do database server in this container. I went back to the anonymous comment that started me on this road and said right there I’d need a pair of containers. In my excitement for a simple solution, I overlooked that bit.
At the end of all this, I might go ahead and try building a docker image that has both WordPress and MySQL in a single container. Maybe it already exists – please leave a comment.
Reading on, Docker had a way to take instructions from a script to se up a cluster of containers. This would do. The same page on docker’s website had a sample YAML script which I could copy and adapt. There was a little bit of confusion about how to express Windows folders (including “C:\”) inside the YAML, but once I worked it out it was all up and running. I had a blank WordPress website running on my Windows machine. Huzzah!
For the benefit of anyone finding this page, here’s what my “volumes” lines in the YAML looked like. (I otherwise used the YAML on docker’s page I linked to above.)
volumes: - "C:/Your/Folder/WP/wordpress:/var/www/html" volumes: - "C:/Your/Folder/WP/db:/var/lib/mysql"
Capital drive letter. Forward slashes including one after the drive letter. No slash on the end. Another colon to separate the Linux side folder,. More forward slashes. All in one string with quotes.
Also, I changed the MySQL password to one I copied from GRC’s secure password generator. No-one should be able to connect to the DB server from outside the container but still, default passwords make me nervous.
My next step was to try out “Multi Site” functionality. I was going to be hosting several websites, so if I could work it by using a single installation of WordPress, upgrading and installing extensions would be a breeze, if it works.
After switching it on by adding a line to the wp-config file, I was informed that MultiSite won’t work with port 8080. That’s annoying. It’ll only work on ports 80 and 443. Grrr.
I was hoping to try a few more things out first but this was a sign I should put this effort on the back-burner and move to my next path of investigation.
Stay tuned for part 3: Cloudflare Tunnel.