roundcube-cleandb.sh: find php and pass a clean PATH to the http user

Roundcube's bin/cleandb.sh starts with '#!/usr/bin/env php'. Under cron
the PATH inherited by 'su' lacked the php binary directory and contained
/root/bin directories not accessible for the http user, so the job failed
with "env: 'php': Permission denied" while it worked in a login shell.

Determine php (PATH or /usr/local/php/bin/php) and run cleandb.sh with
PATH=<php-bin-dir>:/usr/local/bin:/usr/bin:/bin from /tmp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 10:58:55 +01:00
co-authored by Claude Opus 5.5
parent b8c8cd1ef7
commit 67e34c4d13
+18 -1
View File
@@ -252,6 +252,21 @@ if [[ ! -x "$CLEANDB_SCRIPT" ]] ; then
fatal "Script '${CLEANDB_SCRIPT}' is not executable!" fatal "Script '${CLEANDB_SCRIPT}' is not executable!"
fi fi
# - 'cleandb.sh' starts with '#!/usr/bin/env php', so php must be found in
# the PATH of the executing user. Under cron the PATH usually lacks the
# php binary directory (e.g. /usr/local/php/bin) and contains directories
# like /root/bin, which are not accessible for $HTTP_USER ('env: php:
# Permission denied'). So determine php here and pass a clean PATH.
# -
PHP_BIN="$(command -v php 2> /dev/null)"
if [[ -z "$PHP_BIN" ]] && [[ -x "/usr/local/php/bin/php" ]] ; then
PHP_BIN="/usr/local/php/bin/php"
fi
if [[ -z "$PHP_BIN" ]] ; then
fatal "No php binary found (neither in PATH nor '/usr/local/php/bin/php')!"
fi
RUN_PATH="$(dirname "$PHP_BIN"):/usr/local/bin:/usr/bin:/bin"
if $terminal ; then if $terminal ; then
echo "" echo ""
@@ -264,6 +279,7 @@ if $terminal ; then
echo -e " Install directory (via htdocs).......: $INSTALL_DIR" echo -e " Install directory (via htdocs).......: $INSTALL_DIR"
echo -e " Script to be run......................: $CLEANDB_SCRIPT" echo -e " Script to be run......................: $CLEANDB_SCRIPT"
echo -e " Executing user........................: $HTTP_USER" echo -e " Executing user........................: $HTTP_USER"
echo -e " PHP binary............................: $PHP_BIN"
echo "" echo ""
fi fi
@@ -278,7 +294,8 @@ if $terminal ; then
fi fi
echononl " Running 'cleandb.sh' for '${HOSTNAME_WEBMAIL}'.." echononl " Running 'cleandb.sh' for '${HOSTNAME_WEBMAIL}'.."
su -c "$CLEANDB_SCRIPT" -s /bin/bash $HTTP_USER > $log_file 2>&1 su -c "cd /tmp && export PATH=$(printf '%q' "$RUN_PATH") && $(printf '%q' "$CLEANDB_SCRIPT")" \
-s /bin/bash $HTTP_USER > $log_file 2>&1
RC=$? RC=$?
if [[ $RC -eq 0 ]]; then if [[ $RC -eq 0 ]]; then