From 6f8df59432a8040bb759bade9abca3196fd210be Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 22 Mar 2026 21:29:19 -0400 Subject: [PATCH 1/5] refactor(redis): reduce nesting/improve code clarity Signed-off-by: Josh --- docker-entrypoint.sh | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 303aa0052..f858f2fd3 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -85,37 +85,37 @@ file_env() { # Write PHP session config for Redis to /usr/local/etc/php/conf.d/redis-session.ini configure_redis_session() { + local redis_save_path + local redis_auth='' + echo "=> Configuring PHP session handler..." + if [ -z "${REDIS_HOST:-}" ]; then echo "==> Using default PHP session handler" return 0 fi + file_env REDIS_HOST_PASSWORD + + case "$REDIS_HOST" in + /*) + redis_save_path="unix://${REDIS_HOST}" + ;; + *) + redis_save_path="tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}" + ;; + esac + + if [ -n "${REDIS_HOST_PASSWORD+x}" ] && [ -n "${REDIS_HOST_USER+x}" ]; then + redis_auth="?auth[]=${REDIS_HOST_USER}&auth[]=${REDIS_HOST_PASSWORD}" + elif [ -n "${REDIS_HOST_PASSWORD+x}" ]; then + redis_auth="?auth=${REDIS_HOST_PASSWORD}" + fi + echo "==> Using Redis as PHP session handler..." { - file_env REDIS_HOST_PASSWORD echo 'session.save_handler = redis' - # check if redis host is a unix socket path - if [ "$(echo "$REDIS_HOST" | cut -c1-1)" = "/" ]; then - if [ -n "${REDIS_HOST_PASSWORD+x}" ]; then - if [ -n "${REDIS_HOST_USER+x}" ]; then - echo "session.save_path = \"unix://${REDIS_HOST}?auth[]=${REDIS_HOST_USER}&auth[]=${REDIS_HOST_PASSWORD}\"" - else - echo "session.save_path = \"unix://${REDIS_HOST}?auth=${REDIS_HOST_PASSWORD}\"" - fi - else - echo "session.save_path = \"unix://${REDIS_HOST}\"" - fi - # check if redis password has been set - elif [ -n "${REDIS_HOST_PASSWORD+x}" ]; then - if [ -n "${REDIS_HOST_USER+x}" ]; then - echo "session.save_path = \"tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}?auth[]=${REDIS_HOST_USER}&auth[]=${REDIS_HOST_PASSWORD}\"" - else - echo "session.save_path = \"tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}?auth=${REDIS_HOST_PASSWORD}\"" - fi - else - echo "session.save_path = \"tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}\"" - fi + echo "session.save_path = \"${redis_save_path}${redis_auth}\"" echo "redis.session.locking_enabled = 1" echo "redis.session.lock_retries = -1" # redis.session.lock_wait_time is specified in microseconds. From 5be47acc89b7812ace2652df6cce0e5ab1c56762 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 22 Mar 2026 21:54:44 -0400 Subject: [PATCH 2/5] feat(redis): config save_handler w/o modifying ini file in entrypoint Fixes #763 Implements part I of https://github.com/nextcloud/docker/issues/763#issuecomment-3819650853 Signed-off-by: Josh --- docker-entrypoint.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f858f2fd3..97f8de8f9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -83,7 +83,7 @@ file_env() { unset "$fileVar" } -# Write PHP session config for Redis to /usr/local/etc/php/conf.d/redis-session.ini +# Export PHP session config for Redis via environment variables configure_redis_session() { local redis_save_path local redis_auth='' @@ -92,6 +92,11 @@ configure_redis_session() { if [ -z "${REDIS_HOST:-}" ]; then echo "==> Using default PHP session handler" + unset PHP_REDIS_SESSION_HANDLER + unset PHP_REDIS_SESSION_SAVE_PATH + unset PHP_REDIS_SESSION_LOCKING_ENABLED + unset PHP_REDIS_SESSION_LOCK_RETRIES + unset PHP_REDIS_SESSION_LOCK_WAIT_TIME return 0 fi @@ -112,16 +117,13 @@ configure_redis_session() { redis_auth="?auth=${REDIS_HOST_PASSWORD}" fi + export PHP_REDIS_SESSION_HANDLER='redis' + export PHP_REDIS_SESSION_SAVE_PATH="${redis_save_path}${redis_auth}" + export PHP_REDIS_SESSION_LOCKING_ENABLED='1' + export PHP_REDIS_SESSION_LOCK_RETRIES='-1' + export PHP_REDIS_SESSION_LOCK_WAIT_TIME='10000' + echo "==> Using Redis as PHP session handler..." - { - echo 'session.save_handler = redis' - echo "session.save_path = \"${redis_save_path}${redis_auth}\"" - echo "redis.session.locking_enabled = 1" - echo "redis.session.lock_retries = -1" - # redis.session.lock_wait_time is specified in microseconds. - # Wait 10ms before retrying the lock rather than the default 2ms. - echo "redis.session.lock_wait_time = 10000" - } > /usr/local/etc/php/conf.d/redis-session.ini } ######################################################################## From 95b63cd0e3196a98aae492161e926fe4e60fa88d Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 22 Mar 2026 21:58:04 -0400 Subject: [PATCH 3/5] feat(Dockerfile-debian): add env-substituted Redis session settings Signed-off-by: Josh --- Dockerfile-debian.template | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index 72e4d08ce..b1d44ac10 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -120,6 +120,13 @@ RUN { \ echo 'memory_limit=${PHP_MEMORY_LIMIT}'; \ echo 'upload_max_filesize=${PHP_UPLOAD_LIMIT}'; \ echo 'post_max_size=${PHP_UPLOAD_LIMIT}'; \ + echo; \ + echo '; Use Redis for PHP sessions when configured by the entrypoint'; \ + echo 'session.save_handler=${PHP_REDIS_SESSION_HANDLER}'; \ + echo 'session.save_path="${PHP_REDIS_SESSION_SAVE_PATH}"'; \ + echo 'redis.session.locking_enabled=${PHP_REDIS_SESSION_LOCKING_ENABLED}'; \ + echo 'redis.session.lock_retries=${PHP_REDIS_SESSION_LOCK_RETRIES}'; \ + echo 'redis.session.lock_wait_time=${PHP_REDIS_SESSION_LOCK_WAIT_TIME}'; \ } > "${PHP_INI_DIR}/conf.d/nextcloud.ini"; \ \ mkdir /var/www/data; \ From 49cae0b0a265e6fa26b6678be9f556a32f9c420d Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 22 Mar 2026 21:59:39 -0400 Subject: [PATCH 4/5] feat(Dockerfile-alpine): add env-substituted Redis session settings Signed-off-by: Josh --- Dockerfile-alpine.template | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 5fe764bb3..cb647cb84 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -113,6 +113,13 @@ RUN { \ echo 'memory_limit=${PHP_MEMORY_LIMIT}'; \ echo 'upload_max_filesize=${PHP_UPLOAD_LIMIT}'; \ echo 'post_max_size=${PHP_UPLOAD_LIMIT}'; \ + echo; \ + echo '; Use Redis for PHP sessions when configured by the entrypoint'; \ + echo 'session.save_handler=${PHP_REDIS_SESSION_HANDLER}'; \ + echo 'session.save_path="${PHP_REDIS_SESSION_SAVE_PATH}"'; \ + echo 'redis.session.locking_enabled=${PHP_REDIS_SESSION_LOCKING_ENABLED}'; \ + echo 'redis.session.lock_retries=${PHP_REDIS_SESSION_LOCK_RETRIES}'; \ + echo 'redis.session.lock_wait_time=${PHP_REDIS_SESSION_LOCK_WAIT_TIME}'; \ } > "${PHP_INI_DIR}/conf.d/nextcloud.ini"; \ \ mkdir /var/www/data; \ From f9db23097befba0e0a3f7bdb7e2a10fdfca94183 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 23 Mar 2026 08:42:56 -0400 Subject: [PATCH 5/5] chore: ensure PHP never sees empty session config values Signed-off-by: Josh --- docker-entrypoint.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 97f8de8f9..23a65272b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -91,12 +91,13 @@ configure_redis_session() { echo "=> Configuring PHP session handler..." if [ -z "${REDIS_HOST:-}" ]; then - echo "==> Using default PHP session handler" - unset PHP_REDIS_SESSION_HANDLER - unset PHP_REDIS_SESSION_SAVE_PATH - unset PHP_REDIS_SESSION_LOCKING_ENABLED - unset PHP_REDIS_SESSION_LOCK_RETRIES - unset PHP_REDIS_SESSION_LOCK_WAIT_TIME + echo "==> Using default PHP session handler (files)" + # @todo: consider moving to PHP 8.3 missing env variable fallbacks in the ini file itself + export PHP_REDIS_SESSION_HANDLER='files' + export PHP_REDIS_SESSION_SAVE_PATH='' + export PHP_REDIS_SESSION_LOCKING_ENABLED='0' + export PHP_REDIS_SESSION_LOCK_RETRIES='0' + export PHP_REDIS_SESSION_LOCK_WAIT_TIME='0' return 0 fi