Skip to content

Instantly share code, notes, and snippets.

@kundancool
Created September 14, 2025 16:52
Show Gist options
  • Select an option

  • Save kundancool/0dfa08e59893c953ab8d87e4b9b8e688 to your computer and use it in GitHub Desktop.

Select an option

Save kundancool/0dfa08e59893c953ab8d87e4b9b8e688 to your computer and use it in GitHub Desktop.
A shell script to install and configure PHP 8.3 with PHP-FPM, Redis, and common extensions on Alpine Linux. It ensures a www-data user/group exists, configures PHP-FPM to use a secure UNIX socket, and installs a wide range of useful PHP extensions for server environments.
#!/bin/sh
# Alpine PHP 8.3 installation and configuration script
# Run as root
set -e
# -------------------------------
# Install PHP 8.3 + common extensions
# -------------------------------
install_php() {
echo ">>> Installing PHP 8.3 and extensions..."
apk add --no-cache \
php83 php83-common php83-fpm \
php83-cli php83-dev php83-pear \
php83-bcmath php83-bz2 php83-calendar php83-ctype \
php83-curl php83-dba php83-dom php83-exif php83-ffi \
php83-fileinfo php83-ftp php83-gd php83-gettext php83-gmp \
php83-iconv php83-imap php83-intl php83-ldap \
php83-mbstring php83-mysqli php83-mysqlnd \
php83-odbc php83-opcache php83-openssl php83-pcntl \
php83-pdo php83-pdo_dblib php83-pdo_mysql php83-pdo_odbc \
php83-pdo_pgsql php83-pdo_sqlite \
php83-pgsql php83-phar php83-posix php83-pspell \
php83-session php83-shmop php83-simplexml php83-snmp \
php83-soap php83-sockets php83-sodium php83-sqlite3 \
php83-sysvmsg php83-sysvsem php83-sysvshm php83-tidy \
php83-tokenizer php83-xml php83-xmlreader php83-xmlwriter \
php83-xsl php83-zip \
php83-pecl-redis php83-pecl-apcu php83-pecl-igbinary \
php83-pecl-msgpack php83-pecl-imagick php83-pecl-memcached \
php83-pecl-xdebug
}
# -------------------------------
# Configure PHP-FPM
# -------------------------------
configure_php_fpm() {
echo ">>> Configuring PHP-FPM..."
# Enable PHP-FPM in rc
rc-update add php-fpm83 default
# Backup default www pool config
cp /etc/php83/php-fpm.d/www.conf /etc/php83/php-fpm.d/www.conf.bak
# Minimal tweaks for security and performance
sed -i 's/^user = .*/user = nobody/' /etc/php83/php-fpm.d/www.conf
sed -i 's/^group = .*/group = nobody/' /etc/php83/php-fpm.d/www.conf
sed -i 's/^;listen.owner.*/listen.owner = nginx/' /etc/php83/php-fpm.d/www.conf
sed -i 's/^;listen.group.*/listen.group = nginx/' /etc/php83/php-fpm.d/www.conf
sed -i 's/^;listen.mode.*/listen.mode = 0660/' /etc/php83/php-fpm.d/www.conf
# Start service
rc-service php-fpm83 start
}
# -------------------------------
# Configure PHP defaults
# -------------------------------
configure_php_ini() {
echo ">>> Configuring php.ini..."
PHP_INI="/etc/php83/php.ini"
[ -f "$PHP_INI" ] && cp "$PHP_INI" "${PHP_INI}.bak"
sed -i 's/^memory_limit = .*/memory_limit = 512M/' $PHP_INI
sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 50M/' $PHP_INI
sed -i 's/^post_max_size = .*/post_max_size = 50M/' $PHP_INI
sed -i 's/^max_execution_time = .*/max_execution_time = 120/' $PHP_INI
sed -i 's/^;date.timezone =.*/date.timezone = UTC/' $PHP_INI
}
# -------------------------------
# Main
# -------------------------------
main() {
install_php
configure_php_fpm
configure_php_ini
echo ">>> PHP 8.3 + extensions installed and configured!"
echo ">>> PHP-FPM socket available at: /run/php-fpm.sock"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment