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.
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 .
Lets get started
First we need to install docker on our Raspberry Pi:
curl -sSL https://get.docker.com | sh
Now we want to install docker-compose. It helps us to run multiple containers with one configuration file.
sudo apt-get install docker-compose
We can now procceed to clone the repository
git clone https://gitlab.com/nm_hung93/dockerized-wordpress-on-raspberry-pi.git
For this setup i am using:
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.
- [host_directory]/wp:/srv this will be the location where we will install WordPress
- [host_directory]/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
- This is the same as the WordPress installation so that the PHP engine can work with the files
- MariaDB 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
Now being still in the root folder of the repository we can 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.
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