Applicable to:
- Plesk for Linux
Question
How to change PHP handler for multiple domains or for certain domains only via CLI?
Answer
Note: webserver configuration will be reloaded every time when the handler is updated.
-
Connect to the server via SSH.
-
Get a list of registered PHP handlers on a Plesk server by execution of the following command:
# plesk bin php_handler --list
-
Get the list of all domains:
# plesk bin domain --list > /root/domains.txt
-
Edit the
domains.txt
file if some domains should not be changed and execute the command below to change PHP handler for all domains mentioned in thedomains.txt
file:Note: change the plesk-php56-fastcgi directive to the required handler (use handler id from step 2) and specify the nginx-serve-php value (it cannot be set to true when any FastCGI handler is used) in command below.
# cat /root/domains.txt | while read i; do plesk bin domain -u $i -php_handler_id plesk-php56-fastcgi -nginx-serve-php false; done
-
If different handlers assigned to the bunch of domains should be replaced with the other appropriate handlers, e.g. all domains which are using PHP 5.6 FastCGI should be switched to PHP 5.6 FPM, perform the following actions:
-
Download the script from article attachments:
# wget https://support.plesk.com/hc/en-us/article_attachments/360007552194/php_change.zip
-
Unzip downloaded file:
# unzip php_change.zip
-
Make the script executable:
# chmod +x php_change.pl
-
Open the script via any text editor and navigate to the row 33:
CONFIG_TEXT: if ($handler =~ m/^plesk-php56-fastcgi$/g) {
print "Changing $name hander $handler...\n";
plesk bin domain -u $name -php_handler_id plesk-php56-fpm -nginx-serve-php false;
}
elsif($handler =~ m/^plesk-php70-fastcgi$/g) {
print "Changing $name hander $handler...\n";
plesk bin domain -u $name -php_handler_id plesk-php70-fpm -nginx-serve-php false;
}Here, the conditions tell which handlers to which one will be switched:
The first condition - all domains assign to the plesk-php56-fastcgi will be switched to the plesk-php56-fpm handler.
The second condition - all domains assign to the plesk-php70-fastcgi will be switched to the plesk-php70-fpm handler.
Specify the correct handlers using handlers' id from step 2 as also as the nginx-serve-php value (it cannot be set to true when any FastCGI handler is used).
-
Run the script:
# ./php_change.pl
-
Comments
7 comments
or just switch the vendor fastcgi to newer handler on centos for all domains
/usr/local/psa/bin/php_handler --replace -old-id fastcgi -new-id plesk-php71-fastcgi
@Jan Thats correct, it will change php handler for all domains that used this old php handler. But not for all domains on the server.
This method triggers an httpd restart for each domain. Is there a way to do it without restarting httpd for each domain?
@Oxilion, currently this is the only method for changing handler to multiple/all domains.
To minimize effect from downtime, consider applying this instruction during maintenance time frame.
Keep getting exit status 1 on each domain when running this command.
Any ideas?
Hello @Jaden, is there any additional message before "exit status 1"?
For example:
# plesk bin domain -u example.com -php_handler_id plesk-php70-fpm -nginx-serve-php false
The license key is invalid. In order to use Plesk, please obtain and install a new valid license key.
Your license key has expired. To continue using Plesk, buy a non-expiring commercial license key.
exit status 1
In case there is no any, please, enable Plesk debug, reproduce the issue and check Plesk log at /var/log/plesk/panel.log, there will be more specific error message.
Oxilion
I changed the Apache restart interval to 300 (was previously 0), then ran the command - it performed significantly faster than when the restart interval was set to 0. If you do this method don't forget to put it back to 0, and manually restart apache.
Cheers,
C.
Please sign in to leave a comment.