Jumping to the meat and potato a short set of instructions are presented on how you can have a WordPress instance up and running in under 10 minutes on your Raspberry Pi 3+ using docker-compose.
Preperation / Prerequisite
To start off: what you want is a domain name. Since you will be hosting your Raspberry Pi from home and most likely will not have a static IP you also need to tell your domain provider about your changing IP. Luckily no-IP provides both a DDNS service and free domain names. My router also had an option to inform no-IP about my changing IP.
Also don’t forget to forward the ports 80 and 443 which will be incoming traffic to your website. If you are going bigger and get your own domain name you could configure Cloudflare as your nameserver. By establishing a CNAME link to your free domain name at no-IP your new domain name will automatically resolve to the dynamic IP address. An advantage using Cloudflare is, that as a content delivery network, it can cache your website. Additionally it also provides TLS certificates.
Now i assume you already managed all this and have your Raspberry with an installed OS, mine is Raspbian, ready to go . Also ideally we have docker and docker-compose installed, if not just run the following two commands.
curl -sSL https://get.docker.com | sh sudo apt-get install docker-compose
Lets get started – Installing WordPress using docker-compose
First clone the following repository first, this will include all necessary additional configuration files.
git clone https://gitlab.com/nm_hung93/dockerized-wordpress-on-raspberry-pi.git
For a quick overview, the docker-compose file looks like this:
version: '3' services: caddy: # our webserver build for ARM image: hunnguye/caddy-alpine-armv7:1.0.3 volumes: - "./data/wp:/srv" depends_on: - mariadb - php ports: - "80:80" - "443:443" restart: always env_file: - "./data/env_variables/caddy_env" networks: - wordpress php: # the PHP engine based on the official image and added some modules to satisfy WordPress needs image: hunnguye/php7.4-rc-alpine3.1-fpm-mysqli-armv7:7.4-imagick links: - mariadb:mariadb volumes: - "./data/wp:/srv" restart: always networks: - wordpress mariadb: # our out of the box database image: yobasystems/alpine-mariadb volumes: - "./data/db:/var/lib/mysql" - "./data/restore:/restore" restart: always env_file: - "./data/env_variables/mysql_credentials"
We could now configure the mount points of our docker-compose.yml. Per default they will be created in the same folder in which we cloned the repository.
- ./data/wp:/srv > this is the location where we will install WordPress
- ./data/cloudflare_certs:/mnt/cloudflare_certs > i am using cloudflare’s certification and am saving them on my host system you don’t really need this line but it doesn’t break the system either
- ./data/wp:/srv > This is the same mountpoint as the WordPress installation so that the PHP engine can access the same files
- ./data/db:/var/lib/mysqlMariaDB persists its data at /var/lib/mysql. Since we want to save this stateful data we need to mount it to our host system.
It is possible to create a database when initiating the MariaDB container. This can be done through injected environment variables which we specify in /data/env_variables/mysql_credentials.
# set root password for querying inside the container MYSQL_ROOT_PASSWORD=root-pw # below values should match wp-config # this will be your new DB and the credentials you use to initiate your WordPress MYSQL_DATABASE=blog MYSQL_USER=UserX MYSQL_PASSWORD=123456
Downloading and configuring WordPress
The provided repository and docker-compose only act as a skeleton, which we still need to fill with life (WordPress). Therefore, being still in the root folder of the repository we can now download WordPress:
curl -sL http://wordpress.org/latest.tar.gz | tar --strip 1 -xz -C data/wp/www
Navigate to our WordPress installation folder and copy the wp-config-sample.php and edit it. If you are still in your root folder it should look like this:
cd data/wp/www/ cp wp-config-sample.php wp-config.php nano wp-config.php
Change the settings accordingly to our initiated database:
- ‘database_name_here’ into blog
- ‘username_here’ into UserX
- ‘password_here’ into 123456
- ‘localhost’ into mariadb
Save the file with CTRL+X and accept saving the file with Y.
Run WordPress with docker-compose
Now we are all set. Navigate into our root folder (of the repository) again and run docker-compose with
docker-compose -f docker-compose.yml up -d
- -f specifies the file
- -d means detached meaning it runs in the background
The Console should look like this:
Now find the IP address of your Raspberry Pi for example with:
ip addr show
And look out for eth0 or wlan0 depending on your used network interface. Mine is 192.168.2.2. We can now go to another machine inside our network and insert this IP address into our browser.
SUCCESS we did it
Now the next steps you could do are :
- mount the folders to another directory
- edit the Caddyfile such as commenting tls off, and replacing :80 with yourwebsite.com to actually serve your website on https
- edit the /data/env_variables/mysql_credentials file to have more customized database credentials
- if you want to change the upload max size, uncomment the mount of the php.ini file, which is already provided in the repository