
Need some help? We are here for you!We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.
Request support
If like us you are hosting many clients in WHM/cPanel then you most likely have come across the issue of MultiPHP and FPM configuration.
The FPM configuration has 3 main settings, being; Max Requests, Process Idle Timeout and Max Children. By default these settings are inadequate for anything but a hobby website.
cPanel FPM configuration panel has a “system PHP-FPM Configuration” which as you would expect changes the main systems configuration for FPM. However this applies for new accounts created after the settings are changed only… So what about existing accounts?
Well… you have to go edit each and every account one by one – there is no way to assign to every account for some strange reason.
So if you are like us and have 100’s of websites on multiple servers and you want to tweak the PHP-FPM settings for all of them, then a bridge might seem like a good place to take a short walk off.
Kidding aside if you was going to do this through the cPanel interface then you are looking at a very long and frustrating experience. Even if you go and edit the files from the filesystem its going to take you a huge chunk of time and huge potential of mistakes.
I’ve made a very simple bash script which will ask you for each of the 3 values you would like to assign and then will go ahead and update all cPanel accounts with the chosen values, making it super fast and easy to update the configuration files for all your accounts in minutes.
Bash Script: Change PHP-FPM Pool Options for all cPanel accounts
Create a file on your server called “changefpmglobally.sh” and paste the following code into the file:
#!/bin/bash # Prompt the user for values read -p "Enter the new value for pm_max_children (enter 0 to skip): " max_children read -p "Enter the new value for pm_max_requests (enter 0 to skip): " max_requests read -p "Enter the new value for pm_process_idle_timeout (enter 0 to skip): " idle_timeout # Loop through all files and replace the lines for file in /var/cpanel/userdata/*/*.php-fpm.yaml; do if [ "$max_children" -ne 0 ]; then if grep -q "pm_max_children:" "$file"; then sed -i "s/pm_max_children:.*/pm_max_children: $max_children/" "$file" else echo "pm_max_children: $max_children" >> "$file" fi fi if [ "$max_requests" -ne 0 ]; then if grep -q "pm_max_requests:" "$file"; then sed -i "s/pm_max_requests:.*/pm_max_requests: $max_requests/" "$file" else echo "pm_max_requests: $max_requests" >> "$file" fi fi if [ "$idle_timeout" -ne 0 ]; then if grep -q "pm_process_idle_timeout:" "$file"; then sed -i "s/pm_process_idle_timeout:.*/pm_process_idle_timeout: $idle_timeout/" "$file" else echo "pm_process_idle_timeout: $idle_timeout" >> "$file" fi fi echo "Edited file: $file" done #change the global settings file if [ "$max_children" -ne 0 ]; then if grep -q "pm_max_children:" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml"; then sed -i "s/pm_max_children:.*/pm_max_children: $max_children/" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" else echo "pm_max_children: $max_children" >> "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" fi fi if [ "$max_requests" -ne 0 ]; then if grep -q "pm_max_requests:" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml"; then sed -i "s/pm_max_requests:.*/pm_max_requests: $max_requests/" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" else echo "pm_max_requests: $max_requests" >> "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" fi fi if [ "$idle_timeout" -ne 0 ]; then if grep -q "pm_process_idle_timeout:" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml"; then sed -i "s/pm_process_idle_timeout:.*/pm_process_idle_timeout: $idle_timeout/" "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" else echo "pm_process_idle_timeout: $idle_timeout" >> "/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" fi fi echo "Edited file: /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml" # Restart php-fpm echo "Restarting FPM..." /scripts/restartsrv_cpanel_php_fpm echo "FPM restarted, all done!"
chmod the file so that it can be executed:
chmod +x changefpmglobally.sh
now simply run the file in bash, and set your desired values and the script will go ahead and set all the accounts to the specified values for you.
Your welcome :)
Need some help? We are here for you!We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.
Request support