Skip to content

Commit 65a286b

Browse files
committed
feat(web): allow php session storage configuration via environment variables
1 parent 253341b commit 65a286b

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ and the documentation [Use another MySQL instance](docs/EXTERNAL_MYSQL.md) for d
104104
- [TLS Configuration](docs/TLS.md)
105105
- [External MySQL](docs/EXTERNAL_MYSQL.md)
106106
- [Relayhost Configuration](docs/RELAYHOST.md)
107+
- [PHP Sessions](docs/PHP_SESSIONS.md)
107108
- Installation:
108109
- [Kustomize External Database and HTTPS Ingress Example](docs/example-configs/kustomize/external-db-and-https-ingress/README.md)
109110
- [Compose Traefik Reverse Proxy Example](docs/example-configs/compose/traefik-reverse-proxy/README.md)

docs/PHP_SESSIONS.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# PHP Session Configuration
2+
3+
This document explains how to configure PHP sessions in the docker-mailserver project, including both Redis and file-based session storage options.
4+
5+
## Overview
6+
7+
The web service supports configurable PHP session storage through environment variables. By default, sessions are stored in Redis, but you can easily switch to file-based storage or other session handlers.
8+
9+
## Environment Variables
10+
11+
| Variable | Default | Description |
12+
| -------------------------- | ---------------------------------------------------------- | -------------------- |
13+
| `PHP_SESSION_SAVE_HANDLER` | `redis` | Session save handler |
14+
| `PHP_SESSION_SAVE_PATH` | `tcp://${REDIS_HOST}:${REDIS_PORT}?auth=${REDIS_PASSWORD}` | Session save path |
15+
16+
## Session Storage Options
17+
18+
### Redis Sessions (Default)
19+
20+
Redis is the default session storage mechanism, providing fast, scalable session management.
21+
22+
**Configuration:**
23+
24+
```bash
25+
PHP_SESSION_SAVE_HANDLER=redis
26+
PHP_SESSION_SAVE_PATH=tcp://${REDIS_HOST}:${REDIS_PORT}?auth=${REDIS_PASSWORD}
27+
```
28+
29+
### File-Based Sessions
30+
31+
Store sessions as files on the local filesystem.
32+
33+
**Configuration:**
34+
35+
```bash
36+
PHP_SESSION_SAVE_HANDLER=files
37+
PHP_SESSION_SAVE_PATH=/tmp/sessions
38+
```
39+
40+
## Implementation Examples
41+
42+
### Docker Compose Configuration
43+
44+
**Redis Sessions (Default):**
45+
46+
```yaml
47+
services:
48+
web:
49+
environment:
50+
- PHP_SESSION_SAVE_HANDLER=redis
51+
- PHP_SESSION_SAVE_PATH=tcp://redis:6379?auth=${REDIS_PASSWORD}
52+
depends_on:
53+
- redis
54+
```
55+
56+
**File-Based Sessions:**
57+
58+
```yaml
59+
services:
60+
web:
61+
environment:
62+
- PHP_SESSION_SAVE_HANDLER=files
63+
- PHP_SESSION_SAVE_PATH=/tmp/sessions
64+
volumes:
65+
- session_data:/tmp/sessions
66+
```
67+
68+
## PHP Configuration
69+
70+
The session configuration is applied through the PHP configuration file at:
71+
`target/web/rootfs/usr/local/etc/php/conf.d/zzz_app.ini`
72+
73+
```ini
74+
session.save_handler = ${PHP_SESSION_SAVE_HANDLER}
75+
session.save_path = "${PHP_SESSION_SAVE_PATH:-tcp://${REDIS_HOST}:${REDIS_PORT}?auth=${REDIS_PASSWORD}}"
76+
```
77+
78+
This configuration:
79+
80+
- Uses the `PHP_SESSION_SAVE_HANDLER` environment variable
81+
- Falls back to Redis configuration if `PHP_SESSION_SAVE_PATH` is not set

target/web/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ ENV MYSQL_HOST=db \
4949
WAITSTART_TIMEOUT=1m \
5050
ADMIN_VER=${ADMIN_VER} \
5151
DATABASE_URL="mysql://%env(MYSQL_USER)%:%env(MYSQL_PASSWORD)%@%env(MYSQL_HOST)%:%env(MYSQL_PORT)%/%env(MYSQL_DATABASE)%?serverVersion=8.4" \
52-
COMPOSER_ALLOW_SUPERUSER=1
52+
COMPOSER_ALLOW_SUPERUSER=1 \
53+
PHP_SESSION_SAVE_HANDLER=redis
5354

5455
ARG RC_PLUGINS=""
5556
COPY --from=docker.io/roundcube/roundcubemail:1.6.11-fpm@sha256:c7ca21fc0d617e1b866f112250a2b9638a0e237d5a0b345c7b74258ef8fba704 /usr/src/roundcubemail/ /var/www/html/webmail/

target/web/rootfs/usr/local/etc/php/conf.d/zzz_app.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ display_errors = Off
1111
upload_max_filesize = 50M
1212
post_max_size = 50M
1313

14-
session.save_handler = redis
15-
session.save_path = "tcp://${REDIS_HOST}:${REDIS_PORT}?auth=${REDIS_PASSWORD}"
14+
session.save_handler = ${PHP_SESSION_SAVE_HANDLER}
15+
session.save_path = "${PHP_SESSION_SAVE_PATH:-tcp://${REDIS_HOST}:${REDIS_PORT}?auth=${REDIS_PASSWORD}}"

0 commit comments

Comments
 (0)