Get started

How to update PHP settings for every PHP version in cPanel and CloudLinux

A Bash script that applies the same php.ini values to every installed PHP version at once, with a backup of each file it changes.

15 January 2026 · 5 min read

A cPanel server with CloudLinux usually has several PHP versions installed, some from EasyApache 4 (EA-PHP) and some from CloudLinux's ALT-PHP.

Editing each php.ini by hand is slow and easy to get wrong. This guide uses a Bash script to apply the same PHP settings to every installed version at once.

Why use a script

After a fresh cPanel install or a migration, the default PHP settings often cause problems:

  • Uploads fail because upload_max_filesize is too small.
  • Long-running scripts time out.
  • allow_url_include left on is a security risk.
  • Sites show PHP warnings to visitors because display_errors is on.

The script sets your chosen values for every PHP version on the server.

What the script does

It updates the PHP settings for both:

  • EA-PHP (cPanel's EasyApache 4)
  • ALT-PHP (CloudLinux PHP Selector)
  • It backs up each php.ini before changing it.
  • It applies the same directives (memory_limit, max_execution_time and the rest) to every version.
  • It restarts Apache and PHP-FPM so the changes take effect.

The script only replaces directives that are already present and uncommented in php.ini. If a directive is commented out (some files ship with ; max_input_vars = 1000, for example), it is left alone, so check those by hand.

PHP settings used in the script

These are the values the script sets for every PHP version:

DirectiveValueDescription
allow_url_fopenOnAllows opening URLs with file functions
allow_url_includeOffPrevents remote file inclusion
display_errorsOffHides PHP warnings from users
enable_dlOnEnables dynamic loading of extensions
file_uploadsOnAllows file uploads via forms
max_execution_time30Limits script runtime
max_input_time-1No limit on input parsing time
max_input_vars1000Controls number of input variables
memory_limit512MMaximum memory a script can use
post_max_size64MControls POST request size
upload_max_filesize64MMaximum size of an uploaded file
session.gc_maxlifetime1440Session duration (24 min)
zlib.output_compressionOffDisables gzip output compression

The script

Save the following as /root/update-php-settings.sh:

#!/bin/bash
# Update PHP directives for EA-PHP (cPanel EasyApache4) and ALT-PHP (CloudLinux)

# Desired settings
ALLOW_URL_FOPEN="On"
ALLOW_URL_INCLUDE="Off"
DISPLAY_ERRORS="Off"
ENABLE_DL="On"
FILE_UPLOADS="On"
MAX_EXECUTION_TIME="30"
MAX_INPUT_TIME="-1"
MAX_INPUT_VARS="1000"
MEMORY_LIMIT="512M"
POST_MAX_SIZE="64M"
SESSION_GC_MAXLIFETIME="1440"
UPLOAD_MAX_FILESIZE="64M"
ZLIB_OUTPUT_COMPRESSION="Off"

echo "Updating PHP settings for EA-PHP and ALT-PHP..."

#####################################
# Update EA-PHP (EasyApache 4)
#####################################
for php_ini in /opt/cpanel/ea-php*/root/etc/php.ini; do
    if [[ -f "$php_ini" ]]; then
        echo "Updating $php_ini ..."
        cp -p "$php_ini" "$php_ini.bak.$(date +%F_%T)"
        sed -i "s/^allow_url_fopen.*/allow_url_fopen = $ALLOW_URL_FOPEN/" "$php_ini"
        sed -i "s/^allow_url_include.*/allow_url_include = $ALLOW_URL_INCLUDE/" "$php_ini"
        sed -i "s/^display_errors.*/display_errors = $DISPLAY_ERRORS/" "$php_ini"
        sed -i "s/^enable_dl.*/enable_dl = $ENABLE_DL/" "$php_ini"
        sed -i "s/^file_uploads.*/file_uploads = $FILE_UPLOADS/" "$php_ini"
        sed -i "s/^max_execution_time.*/max_execution_time = $MAX_EXECUTION_TIME/" "$php_ini"
        sed -i "s/^max_input_time.*/max_input_time = $MAX_INPUT_TIME/" "$php_ini"
        sed -i "s/^max_input_vars.*/max_input_vars = $MAX_INPUT_VARS/" "$php_ini"
        sed -i "s/^memory_limit.*/memory_limit = $MEMORY_LIMIT/" "$php_ini"
        sed -i "s/^post_max_size.*/post_max_size = $POST_MAX_SIZE/" "$php_ini"
        sed -i "s/^session.gc_maxlifetime.*/session.gc_maxlifetime = $SESSION_GC_MAXLIFETIME/" "$php_ini"
        sed -i "s|^upload_max_filesize.*|upload_max_filesize = $UPLOAD_MAX_FILESIZE|" "$php_ini"
        sed -i "s/^zlib.output_compression.*/zlib.output_compression = $ZLIB_OUTPUT_COMPRESSION/" "$php_ini"
    fi
done

#####################################
# Update ALT-PHP (CloudLinux)
#####################################
for alt_ini in /opt/alt/php*/etc/php.ini; do
    if [[ -f "$alt_ini" ]]; then
        echo "Updating $alt_ini ..."
        cp -p "$alt_ini" "$alt_ini.bak.$(date +%F_%T)"
        sed -i "s/^allow_url_fopen.*/allow_url_fopen = $ALLOW_URL_FOPEN/" "$alt_ini"
        sed -i "s/^allow_url_include.*/allow_url_include = $ALLOW_URL_INCLUDE/" "$alt_ini"
        sed -i "s/^display_errors.*/display_errors = $DISPLAY_ERRORS/" "$alt_ini"
        sed -i "s/^enable_dl.*/enable_dl = $ENABLE_DL/" "$alt_ini"
        sed -i "s/^file_uploads.*/file_uploads = $FILE_UPLOADS/" "$alt_ini"
        sed -i "s/^max_execution_time.*/max_execution_time = $MAX_EXECUTION_TIME/" "$alt_ini"
        sed -i "s/^max_input_time.*/max_input_time = $MAX_INPUT_TIME/" "$alt_ini"
        sed -i "s/^max_input_vars.*/max_input_vars = $MAX_INPUT_VARS/" "$alt_ini"
        sed -i "s/^memory_limit.*/memory_limit = $MEMORY_LIMIT/" "$alt_ini"
        sed -i "s/^post_max_size.*/post_max_size = $POST_MAX_SIZE/" "$alt_ini"
        sed -i "s/^session.gc_maxlifetime.*/session.gc_maxlifetime = $SESSION_GC_MAXLIFETIME/" "$alt_ini"
        sed -i "s|^upload_max_filesize.*|upload_max_filesize = $UPLOAD_MAX_FILESIZE|" "$alt_ini"
        sed -i "s/^zlib.output_compression.*/zlib.output_compression = $ZLIB_OUTPUT_COMPRESSION/" "$alt_ini"
    fi
done

echo "Restarting Apache and PHP-FPM..."
systemctl restart httpd
systemctl restart ea-php*-php-fpm.service 2>/dev/null

echo "✅ All PHP settings updated successfully!"

How to run the script

1. Log in over SSH as root

ssh root@your-server-ip

2. Create the script file

nano /root/update-php-settings.sh

3. Paste the code above and save (Ctrl+O, Enter, Ctrl+X)

4. Make it executable

chmod +x /root/update-php-settings.sh

5. Run the script

sh /root/update-php-settings.sh

6. Wait for the confirmation message

✅ All PHP settings updated successfully!

Changing the values later

To change a setting later, edit the variables at the top of the script and run it again.
It applies the new values to every PHP version and makes another timestamped backup of each file.

Where the script is useful

The script is useful for hosting providers, sysadmins and resellers who look after several PHP versions.
Instead of editing each php.ini by hand, you set the values once and apply them everywhere.

Works on

  • CloudLinux
  • cPanel servers
  • LiteSpeed or Apache setups

Tags:

alt-php cloudlinux

bash script php

cpanel php optimization

ea-php php configuration

linux server php

max_execution_time php

php handler fix

php memory limit fix

php security settings

php upload_max_filesize

php.ini automation

php.ini settings

server php configuration

update php settings

wordpress php performance

Business Guide

How to Choose the Best Web Hosting for Your Business 2026

How to pick a hosting plan that fits your business, your budget and your plans for growth.

Read More →

Troubleshooting

How to Fix PHP Files Downloading Instead of Executing

Why PHP files download instead of running after a move to LiteSpeed, and how to fix the .htaccess handlers causing it.

Read More →