Skip to content

How To Change PHP Versions/Extensions for all users | PHP Selector’s Useful Commands

Table of Contents

Below is the list of useful commands for changing PHP version and extensions, viewing current PHP version used by user, how to change the extensions and PHP options for multiple or single user.

How to Change the PHP version for all users

# selectorctl --change-to-version=7.4 --version=native #this command changes PHP version to 7.4 for all users with native version

Or use the below command to change PHP version for all users 

# cd /var/cpanel/users
# ls -1 | awk '{ print "selectorctl --set-user-current=7.1 --user="$1 }' | sh

To reset user extensions to default settings, use the command below.

selectorctl --list-users --version=7.1 | sed -e 's/,/\n/g' | sed 's/^/selectorctl --reset-user-extensions --version=5.6 --user=/'

If you run the code above;

1. The script will generate a list of all users using PHP 7.1 

2. The script will then generate a separate command to reset the modules for each user 

3. If you add | sh at the end of the command, the modules will be reset for all users that have PHP 7.1.

How to Enable some PHP module for all existing accounts

–for-all-users:Allows to enable/disable extensions for all users with the required PHP version. Works only with --enable-user-extensions or --disable-user-extensions option.

If you want to get a current PHP version for a specific user

selectorctl --user-current --user=UU

To see the list of users using specific PHP version

selectorctl --list-users --version=5.6

If you want to change change PHP version for a single user

selectorctl --set-user-current=5.3 --user=UU

The command for enabling some extensions for a user

selectorctl --enable-user-extensions=pdo,phar --version=5.3 --user=UU

To disable extensions, use a similar command but with the –disable-user-extensions parameter.

Use this command to List user extensions

selectorctl --list-user-extensions --version=5.3 --user=UU

Replace option in users php.ini

selectorctl --replace-options=log_errors:on,display_errors:on --version=5.3 --user=UU