Dashboard
PHP:
8.1.34
OS:
Linux
User:
uid288609
/
/
usr
/
local
/
bin
📤 Upload
📝 New File
📁 New Folder
Close
Editing: php-extensions-enable.sh
#!/bin/bash set -euo pipefail if [ $# -lt 2 ]; then echo "Usage: $0 <php_version> <extension> [<extension> ...]" >&2 echo " extension format: ext.so[:type][:versions]" >&2 echo " examples: ext.so, ext.so:zend, ext.so:zend:8.1,8.2" >&2 echo " versions: comma-separated list of PHP versions (e.g., 8.1,8.2)" >&2 exit 1 fi PHP_VERSION="$1" shift EXTENSIONS=("$@") PHP_PATH="/opt/php${PHP_VERSION}" if [ ! -d "${PHP_PATH}" ]; then echo "PHP version ${PHP_VERSION} does not exist" >&2 exit 1 fi EXT_DIR=$(${PHP_PATH}/bin/php-config --extension-dir) if [ -z "${EXT_DIR}" ]; then echo "Failed to get extension directory for PHP ${PHP_VERSION}" >&2 exit 1 fi # Function to get priority based on extension name get_extension_priority() { local ext_name="$1" case "${ext_name}" in ioncube*) echo "00" ;; ZendGuardLoader) echo "20" ;; opcache) echo "30" ;; http) echo "70" ;; *) echo "50" ;; esac } # Parse extension list and enable each extension for ext_spec in "${EXTENSIONS[@]}"; do # Parse from pattern like "ext.so:type:versions" # Examples: ext.so, ext.so:zend, ext.so:zend:8.1,8.2, ext.so::8.1,8.2 IFS=':' read -r ext_pattern ext_type ext_versions <<< "${ext_spec}" # Set defaults if empty ext_type="${ext_type:-}" ext_versions="${ext_versions:-}" # Check if specific PHP versions are required if [ -n "${ext_versions}" ]; then version_found=false IFS=',' read -ra version_list <<< "${ext_versions}" for v in "${version_list[@]}"; do if [ "$v" = "${PHP_VERSION}" ]; then version_found=true break fi done if [ "${version_found}" = false ]; then continue fi fi # Find matching .so files for so_file in ${EXT_DIR}/${ext_pattern}; do if [ -f "${so_file}" ]; then ext_file_name=$(basename "${so_file}" .so | tr -d '.') ext_priority=$(get_extension_priority "${ext_file_name}") conf_file="${PHP_PATH}/etc/conf.d/${ext_priority}_${ext_file_name}.ini" if [ "${ext_type}" = "zend" ]; then ext_directive="zend_extension" else ext_directive="extension" fi cat > "${conf_file}" <<EOF ${ext_directive}=${so_file} EOF else echo "Warning: Extension file not found: ${so_file}" >&2 fi done done
Save
Cancel