Little script to validate server setup for Joomla 5.3 and PHP 8.3 on Ubuntu #16

Open
opened 2025-08-14 16:09:55 +00:00 by Llewellyn · 0 comments
Owner
#!/usr/bin/env bash
# setup-php83-like-joomla-php-only.sh
# Install PHP 8.3 + extensions to mirror Joomla's php:8.3-apache Dockerfile (PHP-only).
# No Apache/FPM setup, no HTTP checks, no non-PHP packages.
# Works on Ubuntu 22.04/24.04 (and Debian-based systems with appropriate repos).

set -euo pipefail

# ---------------- helpers ----------------
log()  { printf "\n\033[1;34m[INFO]\033[0m %s\n" "$*"; }
ok()   { printf "\033[1;32m[OK]\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*"; }
err()  { printf "\033[1;31m[ERR]\033[0m %s\n" "$*"; }

need_root() {
	if [[ $EUID -ne 0 ]]; then
		err "Please run as root (e.g., sudo bash $0)"; exit 1
	fi
}

is_cmd() { command -v "$1" >/dev/null 2>&1; }

php_ini_dir_for_sapi() {
	# Prefer CLI INI dir for system-wide config of extensions
	php -i 2>/dev/null | awk -F'=> ' '/Scan this dir for additional .ini files/ {print $2; exit}'
}

# ---------------- main ----------------
need_root
export DEBIAN_FRONTEND=noninteractive

log "Preparing APT..."
apt-get update -y
apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release apt-transport-https

dist_id=$(lsb_release -is 2>/dev/null || echo Ubuntu)

log "Ensuring PHP 8.3 packages are available..."
# Ubuntu 24.04 ships PHP 8.3. Ubuntu 22.04 may need Ondřej's PPA.
if [[ "$dist_id" == "Ubuntu" ]]; then
	apt-get install -y --no-install-recommends software-properties-common
	if ! apt-cache policy php8.3 | grep -q 'Candidate:'; then
		log "Adding Ondřej Surý PPA for PHP..."
		add-apt-repository -y ppa:ondrej/php
		apt-get update -y
	fi
else
	warn "Non-Ubuntu Debian-based system detected. Proceeding with available repos."
fi

log "Installing PHP 8.3 core runtime..."
apt-get install -y --no-install-recommends \
	php8.3 php8.3-cli php8.3-common

log "Installing PHP 8.3 extensions to match the container..."
apt-get install -y --no-install-recommends \
	php8.3-bz2 \
	php8.3-bcmath \
	php8.3-exif \
	php8.3-gd \
	php8.3-gmp \
	php8.3-intl \
	php8.3-ldap \
	php8.3-mysql \
	php8.3-pgsql \
	php8.3-zip \
	php8.3-opcache \
	php8.3-apcu \
	php8.3-redis \
	php8.3-memcached \
	php-imagick

ok "PHP 8.3 and required extensions installed."

log "Applying OPcache recommended settings (as in the Dockerfile)..."
cli_conf_d="$(php_ini_dir_for_sapi || true)"
if [[ -z "${cli_conf_d}" || ! -d "${cli_conf_d}" ]]; then
	# Fallback for typical Ubuntu path
	cli_conf_d="/etc/php/8.3/cli/conf.d"
	mkdir -p "$cli_conf_d"
fi

cat > "${cli_conf_d}/90-opcache-recommended.ini" <<'INI'
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
INI

log "Applying PHP error logging settings (as in the Dockerfile)..."
cat > "${cli_conf_d}/90-error-logging.ini" <<'INI'
error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /dev/stderr
log_errors_max_len = 1024
ignore_repeated_errors = On
ignore_repeated_source = Off
html_errors = Off
INI

ok "INI settings applied to CLI. (If you later use FPM or Apache SAPI, copy these files to their conf.d dir.)"

# ---------------- validation ----------------
log "Validating PHP version == 8.3..."
if php -v | grep -qE '^PHP 8\.3\.'; then
	ok "PHP 8.3 detected."
else
	err "PHP is not 8.3. Found: $(php -v | head -n1 || echo 'unknown')"
	exit 2
fi

log "Validating required extensions are loaded..."
# Map of expected modules (using php -m names)
required_modules=(
	bz2
	bcmath
	exif
	gd
	gmp
	intl
	ldap
	mysqli
	pdo_mysql
	pgsql
	pdo_pgsql
	zip
	opcache
	apcu
	memcached
	redis
	imagick
)

missing=()
mods="$(php -m | tr '[:upper:]' '[:lower:]')"
for m in "${required_modules[@]}"; do
	if ! grep -q "^${m}$" <<<"$mods"; then
		missing+=("$m")
	fi
done

if [[ ${#missing[@]} -eq 0 ]]; then
	ok "All required extensions are active: ${required_modules[*]}"
else
	err "Missing PHP extensions: ${missing[*]}"
	err "Try: apt-get install -y $(printf 'php8.3-%s ' "${missing[@]}" | sed 's/php8.3-opcache/opcache/;s/php8.3-apcu/apcu/;s/php8.3-memcached/memcached/;s/php8.3-redis/redis/') or verify module names."
	exit 3
fi

ok "Setup complete. PHP-only environment matches the container's PHP feature set."
``` #!/usr/bin/env bash # setup-php83-like-joomla-php-only.sh # Install PHP 8.3 + extensions to mirror Joomla's php:8.3-apache Dockerfile (PHP-only). # No Apache/FPM setup, no HTTP checks, no non-PHP packages. # Works on Ubuntu 22.04/24.04 (and Debian-based systems with appropriate repos). set -euo pipefail # ---------------- helpers ---------------- log() { printf "\n\033[1;34m[INFO]\033[0m %s\n" "$*"; } ok() { printf "\033[1;32m[OK]\033[0m %s\n" "$*"; } warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*"; } err() { printf "\033[1;31m[ERR]\033[0m %s\n" "$*"; } need_root() { if [[ $EUID -ne 0 ]]; then err "Please run as root (e.g., sudo bash $0)"; exit 1 fi } is_cmd() { command -v "$1" >/dev/null 2>&1; } php_ini_dir_for_sapi() { # Prefer CLI INI dir for system-wide config of extensions php -i 2>/dev/null | awk -F'=> ' '/Scan this dir for additional .ini files/ {print $2; exit}' } # ---------------- main ---------------- need_root export DEBIAN_FRONTEND=noninteractive log "Preparing APT..." apt-get update -y apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release apt-transport-https dist_id=$(lsb_release -is 2>/dev/null || echo Ubuntu) log "Ensuring PHP 8.3 packages are available..." # Ubuntu 24.04 ships PHP 8.3. Ubuntu 22.04 may need Ondřej's PPA. if [[ "$dist_id" == "Ubuntu" ]]; then apt-get install -y --no-install-recommends software-properties-common if ! apt-cache policy php8.3 | grep -q 'Candidate:'; then log "Adding Ondřej Surý PPA for PHP..." add-apt-repository -y ppa:ondrej/php apt-get update -y fi else warn "Non-Ubuntu Debian-based system detected. Proceeding with available repos." fi log "Installing PHP 8.3 core runtime..." apt-get install -y --no-install-recommends \ php8.3 php8.3-cli php8.3-common log "Installing PHP 8.3 extensions to match the container..." apt-get install -y --no-install-recommends \ php8.3-bz2 \ php8.3-bcmath \ php8.3-exif \ php8.3-gd \ php8.3-gmp \ php8.3-intl \ php8.3-ldap \ php8.3-mysql \ php8.3-pgsql \ php8.3-zip \ php8.3-opcache \ php8.3-apcu \ php8.3-redis \ php8.3-memcached \ php-imagick ok "PHP 8.3 and required extensions installed." log "Applying OPcache recommended settings (as in the Dockerfile)..." cli_conf_d="$(php_ini_dir_for_sapi || true)" if [[ -z "${cli_conf_d}" || ! -d "${cli_conf_d}" ]]; then # Fallback for typical Ubuntu path cli_conf_d="/etc/php/8.3/cli/conf.d" mkdir -p "$cli_conf_d" fi cat > "${cli_conf_d}/90-opcache-recommended.ini" <<'INI' opcache.enable=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=2 INI log "Applying PHP error logging settings (as in the Dockerfile)..." cat > "${cli_conf_d}/90-error-logging.ini" <<'INI' error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR display_errors = Off display_startup_errors = Off log_errors = On error_log = /dev/stderr log_errors_max_len = 1024 ignore_repeated_errors = On ignore_repeated_source = Off html_errors = Off INI ok "INI settings applied to CLI. (If you later use FPM or Apache SAPI, copy these files to their conf.d dir.)" # ---------------- validation ---------------- log "Validating PHP version == 8.3..." if php -v | grep -qE '^PHP 8\.3\.'; then ok "PHP 8.3 detected." else err "PHP is not 8.3. Found: $(php -v | head -n1 || echo 'unknown')" exit 2 fi log "Validating required extensions are loaded..." # Map of expected modules (using php -m names) required_modules=( bz2 bcmath exif gd gmp intl ldap mysqli pdo_mysql pgsql pdo_pgsql zip opcache apcu memcached redis imagick ) missing=() mods="$(php -m | tr '[:upper:]' '[:lower:]')" for m in "${required_modules[@]}"; do if ! grep -q "^${m}$" <<<"$mods"; then missing+=("$m") fi done if [[ ${#missing[@]} -eq 0 ]]; then ok "All required extensions are active: ${required_modules[*]}" else err "Missing PHP extensions: ${missing[*]}" err "Try: apt-get install -y $(printf 'php8.3-%s ' "${missing[@]}" | sed 's/php8.3-opcache/opcache/;s/php8.3-apcu/apcu/;s/php8.3-memcached/memcached/;s/php8.3-redis/redis/') or verify module names." exit 3 fi ok "Setup complete. PHP-only environment matches the container's PHP feature set." ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: octoleo/octojoom#16
No description provided.