Question
How do I change all of my domains from EA-PHP (ea-php*) to ALT-PHP (alt-php*) from the command line, keeping the same PHP version for each domain?
Answer
cPanel sets the PHP version per domain (vhost), so the version is changed with the php_set_vhost_versions WHM API function. The commands below read each domain's current ea-php* version and set the matching alt-php* version. For example, ea-php81 becomes alt-php81.
Requirements: CloudLinux with alt-php, or PHP ELS integrated into MultiPHP Manager, and the matching alt-php* versions installed on the server.
- Log in to the server as
rootvia SSH. -
Confirm the alt-php versions are available to MultiPHP Manager. Each version your domains use should appear as
alt-php*:# whmapi1 php_get_installed_versions
-
Preview the changes. This prints each domain, its current EA-PHP version, and the ALT-PHP version it will be changed to:
# whmapi1 php_get_vhost_versions --output=json | jq -r '.data.versions[] | select(.version|startswith("ea-php")) | "\(.vhost): \(.version) -> alt-php\(.version|ltrimstr("ea-php"))"'
Note: Example output:
example.com: ea-php81 -> alt-php81Apply the changes:
# whmapi1 php_get_vhost_versions --output=json | jq -r '.data.versions[] | select(.version|startswith("ea-php")) | "\(.vhost) alt-php\(.version|ltrimstr("ea-php"))"' | while read v n; do whmapi1 php_set_vhost_versions version="$n" vhost-0="$v"; done
To revert from ALT-PHP to EA-PHP
# whmapi1 php_get_vhost_versions --output=json | jq -r '.data.versions[] | select(.version|startswith("alt-php")) | "\(.vhost) ea-php\(.version|ltrimstr("alt-php"))"' | while read v n; do whmapi1 php_set_vhost_versions version="$n" vhost-0="$v"; done
Comments
0 comments
Please sign in to leave a comment.