Skip to content

Commit b1d67ed

Browse files
authored
Merge pull request #759 from Paraphraser/20240328-wordpress-master
2024-03-28 Adds WordPress - master branch - PR 1 of 2
2 parents c0c4630 + e95f0e2 commit b1d67ed

File tree

2 files changed

+306
-0
lines changed

2 files changed

+306
-0
lines changed

.templates/wordpress/service.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
wordpress:
2+
container_name: wordpress
3+
image: wordpress
4+
restart: unless-stopped
5+
environment:
6+
TZ: ${TZ:-Etc/UTC}
7+
WORDPRESS_DB_HOST: wordpress_db
8+
WORDPRESS_DB_USER: ${WORDPRESS_DB_USER:-wordpress}
9+
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD:?eg echo WORDPRESS_DB_PASSWORD=userPassword >>~/IOTstack/.env}
10+
WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME:-wordpress}
11+
volumes:
12+
- ./volumes/wordpress/html:/var/www/html
13+
ports:
14+
- "8084:80"
15+
hostname: ${WORDPRESS_HOSTNAME:?eg echo WORDPRESS_HOSTNAME=hostname >>~/IOTstack/.env}
16+
networks:
17+
- default
18+
- nextcloud
19+
depends_on:
20+
- wordpress_db
21+
22+
wordpress_db:
23+
container_name: wordpress_db
24+
build: ./.templates/mariadb/.
25+
restart: unless-stopped
26+
environment:
27+
TZ: ${TZ:-Etc/UTC}
28+
MYSQL_ROOT_PASSWORD: ${WORDPRESS_ROOT_PASSWORD:?eg echo WORDPRESS_ROOT_PASSWORD=rootPassword >>~/IOTstack/.env}
29+
MYSQL_USER: ${WORDPRESS_DB_USER:-wordpress}
30+
MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD:?eg echo WORDPRESS_DB_PASSWORD=userPassword >>~/IOTstack/.env}
31+
MYSQL_DATABASE: ${WORDPRESS_DB_NAME:-wordpress}
32+
volumes:
33+
- ./volumes/wordpress/db:/config
34+
- ./volumes/wordpress/db_backup:/backup
35+
networks:
36+
- nextcloud

docs/Containers/WordPress.md

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# WordPress
2+
3+
WordPress is a web content-management system.
4+
5+
## Resources
6+
7+
- [WordPress home page](https://wordpress.org)
8+
9+
- [documentation](https://wordpress.org/documentation/)
10+
11+
- [DockerHub](https://hub.docker.com/_/wordpress)
12+
- [GitHub](https://github.com/docker-library/wordpress)
13+
14+
## Overview
15+
16+
You need to perform two steps before WordPress can be launched:
17+
18+
1. [Install the service definition](#wpInst).
19+
2. [Configure the environment](#wpConfig).
20+
21+
Note:
22+
23+
* Do **not** "up" your stack until you have completed step 2.
24+
25+
<a name="wpInst"></a>
26+
## Install the service definition
27+
28+
Be in the correct directory:
29+
30+
``` console
31+
$ cd ~/IOTstack
32+
```
33+
34+
### option 1 - the IOTstack menu
35+
36+
1. Launch the menu
37+
38+
``` console
39+
$ ./menu.sh
40+
```
41+
42+
2. Choose "Build Stack".
43+
3. Place the cursor on "wordpress" and press <kbd>space</kbd> to select it.
44+
4. Press <kbd>enter</kbd> to build the stack.
45+
5. Place the cursor on "Exit" and press <kbd>enter</kbd>.
46+
47+
### option 2 - manual from IOTstack templates
48+
49+
When IOTstack is cloned from GitHub, the default for your local copy of the repository is to be on the "master" branch. Master-branch templates are left-shifted by two spaces with respect to how they need to appear in `docker-compose.yml`. The following `sed` command prepends two spaces to the start of each line:
50+
51+
``` console
52+
$ sed -e "s/^/ /" ./.templates/wordpress/service.yml >>docker-compose.yml
53+
```
54+
55+
Templates on the "old-menu" branch already have proper alignment, so `cat` can be used:
56+
57+
``` console
58+
$ cat ./.templates/wordpress/service.yml >>docker-compose.yml
59+
```
60+
61+
<a name="wpConfig"></a>
62+
## Configure the environment
63+
64+
### check dependency
65+
66+
The password-generation steps in the [next section](#pwgen) assume `uuidgen` is available on your system. The following command installs `uuidgen` if it is not present already:
67+
68+
``` console
69+
$ [ -z "$(which uuidgen)" ] && sudo apt update && sudo apt install -y uuid-runtime
70+
```
71+
72+
<a name="pwgen"></a>
73+
### generate passwords
74+
75+
WordPress relies on MariaDB, and MariaDB requires both a user password and a root password. You can generate the passwords like this:
76+
77+
``` console
78+
$ echo "WORDPRESS_DB_PASSWORD=$(uuidgen)" >>~/IOTstack/.env
79+
$ echo "WORDPRESS_ROOT_PASSWORD=$(uuidgen)" >>~/IOTstack/.env
80+
```
81+
82+
Key points:
83+
84+
1. You will not need to know either of these passwords in order to use WordPress.
85+
86+
> These passwords govern access to the WordPress database (the `wordpress_db` container). WordPress (the `wordpress` container) has a separate system of credentials. You set up an administrator account the first time you [login to WordPress](#wordPressGUI).
87+
88+
2. You will not need to know either password in order to use the `mysql` command line interface to inspect the WordPress database. See [accessing the MariaDB command line interface](#mariaDBcli).
89+
3. The WordPress database container does not expose any ports to the outside world. That means you can't use general-purpose MariaDB/MySQL GUI-based front-ends to reach the WordPress database.
90+
4. Both passwords are applied when the MariaDB container is first initialised. Changing either password value in `.env` will break your installation.
91+
92+
<a name="setHostname"></a>
93+
### set hostname
94+
95+
WordPress (running inside the container) needs to know the domain name of the host on which the container is running. You can satisfy the requirement like this:
96+
97+
``` console
98+
$ echo "WORDPRESS_HOSTNAME=$HOSTNAME.local" >>~/IOTstack/.env
99+
```
100+
101+
The above assumes the host is advertising a multicast domain name. This is a safe assumption for Raspberry Pis but may not necessarily be applicable in other situations. If your host is associated with a fully-qualified domain name (A record or CNAME), you can use that instead. For example:
102+
103+
``` console
104+
$ echo "WORDPRESS_HOSTNAME=iot-hub.my.domain.com" >>~/IOTstack/.env
105+
```
106+
107+
### checking your WordPress environment values
108+
109+
You can confirm that the passwords and hostname have been added to `.env` like this:
110+
111+
```
112+
$ grep "^WORDPRESS" ~/IOTstack/.env
113+
WORDPRESS_DB_PASSWORD=41dcbe76-9c39-4c7f-bd65-2f0421bccbeb
114+
WORDPRESS_ROOT_PASSWORD=ee749d72-f1a5-4bc0-b182-21e8284f9fd2
115+
WORDPRESS_HOSTNAME=raspberrypi.local
116+
```
117+
118+
### alternative method
119+
120+
If you prefer to keep your environment values inline in your `docker-compose.yml` rather than in the `.env` file then you can achieve the same result by editing the service definitions as follows:
121+
122+
* `wordpress`:
123+
124+
``` yaml
125+
environment:
126+
WORDPRESS_DB_PASSWORD: «yourUserPasswordHere»
127+
hostname: «hostname».«domain»
128+
```
129+
130+
* `wordpress_db`:
131+
132+
``` yaml
133+
environment:
134+
MYSQL_ROOT_PASSWORD: «yourRootPasswordHere»
135+
MYSQL_PASSWORD: «yourUserPasswordHere»
136+
```
137+
138+
## Starting WordPress
139+
140+
``` console
141+
$ cd ~/IOTstack
142+
$ docker-compose up -d wordpress
143+
```
144+
145+
This starts both WordPress and its database.
146+
147+
<a name="wordPressGUI"></a>
148+
## Accessing the WordPress GUI
149+
150+
Use a URL in the following form, where `«host»` should be the value you chose at [set hostname](#setHostname).
151+
152+
```
153+
http://«host»:8084
154+
```
155+
156+
Examples:
157+
158+
* `http://raspberrypi.local:8084`
159+
* `http://iot-hub.my.domain.com:8084`
160+
161+
You will be prompted to:
162+
163+
1. Set your language; and
164+
2. Create your administrator account.
165+
166+
After that, you should refer to the [WordPress documentation](https://wordpress.org/documentation/).
167+
168+
<a name="aboutMariaDB"></a>
169+
## About MariaDB
170+
171+
The MariaDB instance associated with WordPress is **private** to WordPress. It is included along with the WordPress service definition. You do **not** have to select MariaDB in the IOTstack menu.
172+
173+
> There is nothing stopping you from *also* selecting MariaDB in the IOTstack menu. Multiple instances of MariaDB will coexist quite happily but they are separate and distinct Relational Database Manager Systems (RDBMS).
174+
175+
<a name="mariaDBcli"></a>
176+
### Accessing the MariaDB command line interface
177+
178+
If you need inspect or manipulate the WordPress database, begin by opening a shell into the WordPress MariaDB container:
179+
180+
```
181+
$ docker exec -it wordpress_db bash
182+
```
183+
184+
While you are in the shell, you can use the `MYSQL_ROOT_PASSWORD` environment variable to reference the root password. For example:
185+
186+
``` console
187+
# mysql -p$MYSQL_ROOT_PASSWORD
188+
Welcome to the MariaDB monitor. Commands end with ; or \g.
189+
Your MariaDB connection id is 169
190+
Server version: 10.11.6-MariaDB-log Alpine Linux
191+
192+
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
193+
194+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
195+
196+
MariaDB [(none)]>
197+
```
198+
199+
Note:
200+
201+
* There is no space between the `-p` and `$MYSQL_ROOT_PASSWORD`. If you insert a space, `mysql` will prompt you to enter the password interactively.
202+
203+
Once you have opened a session using `mysql`, you can execute MySQL commands. For example:
204+
205+
```
206+
MariaDB [(none)]> show databases;
207+
+--------------------+
208+
| Database |
209+
+--------------------+
210+
| information_schema |
211+
| mysql |
212+
| performance_schema |
213+
| sys |
214+
| wordpress |
215+
+--------------------+
216+
5 rows in set (0.010 sec)
217+
```
218+
219+
To exit `mysql`, either press <kbd>control</kbd>+<kbd>d</kbd> or use the `exit` command:
220+
221+
```
222+
MariaDB [(none)]> exit
223+
Bye
224+
225+
#
226+
```
227+
228+
Similarly, <kbd>control</kbd>+<kbd>d</kbd> or `exit` will terminate the container's `bash` shell and return you to the host's command line.
229+
230+
## References to `nextcloud`
231+
232+
Both the `wordpress` and `wordpress_db` service definitions connect to the `nextcloud` **network**.
233+
234+
> Please note the emphasis on "**network**".
235+
236+
The `nextcloud` network is an internal *private* network created by `docker-compose` to facilitate data-communications between a user-facing service (like WordPress) and an associated database back-end (like MariaDB).
237+
238+
The NextCloud container was the first to use the private-network strategy so the "nextcloud" name is an accident of history. In an ideal world, the network would be renamed to something which more accurately reflected its purpose, like "databases". Unfortunately, the IOTstack menu lacks the facilities needed to update *existing* deployments so the most likely result of any attempt at renaming would be to break existing stacks.
239+
240+
At runtime, the `nextcloud` network has the name `iotstack_nextcloud`, and exists alongside the `iotstack_default` network which is shared by other IOTstack containers.
241+
242+
The material point is that, even though WordPress has nothing to do with NextCloud, the references to the `nextcloud` network are are not mistakes. They are intentional.
243+
244+
## <a name="cleanSlate"></a>Getting a clean slate
245+
246+
If you start the WordPress container and *then* decide that you need to change its [environment variables](#wpConfig), you must first erase the container's persistent store:
247+
248+
``` console
249+
$ cd ~/IOTstack
250+
$ docker-compose down wordpress wordpress_db
251+
$ sudo rm -rf ./volumes/wordpress
252+
```
253+
254+
Notes:
255+
256+
* Both the `wordpress` and `wordpress_db` containers need to be taken down before the persistent store can be removed safely.
257+
* Be very careful with the `sudo rm` command. Double-check *before* pressing the <kbd>return</kbd> key!
258+
259+
Once the persistent store has been erased, you can change the [environment variables](#wpConfig).
260+
261+
When you are ready, start WordPress again:
262+
263+
``` console
264+
$ cd ~/IOTstack
265+
$ docker-compose up -d wordpress
266+
```
267+
268+
Note:
269+
270+
* The `wordpress_db` container does not need to be brought up explicitly. It is started automatically as a by-product of starting `wordpress`.

0 commit comments

Comments
 (0)