Skip to content

Instantly share code, notes, and snippets.

@mrl22
Last active July 23, 2024 12:38
Show Gist options
  • Save mrl22/ad84e443f3658dd2904784706c5b44f7 to your computer and use it in GitHub Desktop.
Save mrl22/ad84e443f3658dd2904784706c5b44f7 to your computer and use it in GitHub Desktop.
Forge Recipe: Update PHP-FPM Settings - All Installed PHP Versions
#!/usr/bin/env bash
declare -A replacers
# Define the settings to be replaced or added
replacers[upload_max_filesize]=500M
replacers[post_max_size]=500M
replacers[max_input_vars]=5000
replacers[memory_limit]=512M
replacers[max_execution_time]=360
replacers[max_input_time]=360
# Loop through all php.ini files in /etc/php/*/fpm/
for PHP_INI_FILE in /etc/php/*/fpm/php.ini; do
echo "Processing file: $PHP_INI_FILE"
for i in "${!replacers[@]}"; do
echo "Setting value of $i to ${replacers[$i]}"
# Check if the configuration setting exists in the file
if grep -q "^$i" $PHP_INI_FILE; then
# If it exists, replace the existing value with the new value
sed -i "s/^\($i\).*/\1 = ${replacers[$i]}/" $PHP_INI_FILE
else
# If it does not exist, append the setting to the file
echo "$i = ${replacers[$i]}" >> $PHP_INI_FILE
fi
done
# Restart the corresponding PHP-FPM service to apply changes
PHP_VERSION=$(echo $PHP_INI_FILE | awk -F'/' '{print $4}')
echo "Restarting PHP-FPM service for version $PHP_VERSION"
service php$PHP_VERSION-fpm restart
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment