• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved 503 error after changing php_handler_id for site

bbeckford

New Pleskian
Server operating system version
CentOS Linux 7.9.2009 (Core)
Plesk version and microupdate number
Plesk Obsidian 18.0.53 Update #2
Hi all,

I have some PHP software that updates via a bash script.

As part of that script I want to update the PHP handler for a given domain, I'm attempting to do that like so:

Bash:
plesk bin site -u "mydomain.com" -php_handler_id plesk-php82-fpm

That command runs ok and I can see in the PHP settings for mydomain.com that the PHP version is now 8.2.8, but the site now just displays a "503 Service Unavailable" error, and in the logs I see the following:

2023-07-13 15:02:14Error111.222.333.444503GET /cp/config/?mode=update&create_backup=false HTTP/1.0
https://ben.ccd.systems/cp/config/
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
697Apache SSL/TLS access
2023-07-13 15:02:14Error(2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/www/vhosts/system/mydomain.com/php-fpm.sock (*) failedApache error
2023-07-13 15:02:14Error111.222.333.444AH01079: failed to make connection to backend: httpd-UDS, referer: https://mydomain.com/cp/config/Apache error

After Googling some more I tried running the following command:

Bash:
plesk bin php_settings -u

...this fixes it but this takes a very long time as it's updating all domains on the system.

Is there a secondary command I should be calling after changing the handler?

Changing PHP from 7.4 to 8.2 and back again from the Plesk GUI works perfectly.

Thanks!
 
Yes I've tried that too but no change :(

FYI my script looks like this:

Bash:
plesk bin site -u "${domain}" -php_handler_id "${latest_php_handler_id}"
plesk bin site --update-php-settings "${domain}"
plesk repair web -php-handlers -php-fpm-configuration -y "${domain}"
 
The only thing I can suggest is to reload the webserver configuration after the change. However, the "repair web" should already do that. I do not know why it does not work in this specific case.
 
Ok so I added the following and that seems to have done the trick, thanks for your help, Peter!

Bash:
plesk bin domain --update-web-server-settings "${domain}"

For those searching, this is my full code:

Bash:
# set base php version target, eg 8 for php 8.x
readonly target_php_version=8
# get the current php_handler_id for the domain, yields for eg plesk-php82-fpm
readonly php_handler_id=$(plesk db -Ne "select DISTINCT h.php_handler_id from domains d join hosting h on h.dom_id=d.id WHERE d.name = '${domain}';")
# extract longer form php number from $php_handler_id, eg plesk-php82-fpm --> 82
readonly current_php_handler_id_number=$(echo "${php_handler_id}" | grep -oP '(?<=php)(.*)(?=-fpm)')
# multiply target_php_version by 10 to get the minimum php version id number, eg 8 * 10 = 80
readonly target_php_version_min_id_number=$((target_php_version * 10))

# if current_php_handler_id_number is less than the target_php_version_min_id_number
if [ "${current_php_handler_id_number}" -lt "${target_php_version_min_id_number}" ]
then
    # get the latest installed target_php_version, eg 82 (8.2)
    readonly latest_php_handler_id=$(plesk db -Ne "SELECT name FROM ServiceNodeEnvironment WHERE section = 'phphandlers' AND name REGEXP '^plesk-php${target_php_version}[0-9]+-fpm\$' ORDER BY ServiceNodeEnvironment.name DESC LIMIT 1;");
    # update the domain to use the latest php version
    plesk bin site -u "${domain}" -php_handler_id "${latest_php_handler_id}"
    # run a series of plesk repair commands which all seem to be needed to get the domain working again (see https://talk.plesk.com/threads/503-error-after-changing-php_handler_id-for-site.370625/)
    plesk bin site --update-php-settings "${domain}"
    plesk repair web -php-handlers -php-fpm-configuration -y "${domain}"
    plesk bin domain --update-web-server-settings "${domain}"
fi
 
It occurred to me that the latest PHP version available on the server might not be sufficient to warrant an update, so I added a condition for that:

Bash:
# set base php version target, eg 8 for php 8.x
readonly target_php_version=8
# get the current php_handler_id for the domain, yields for eg plesk-php82-fpm
readonly php_handler_id=$(plesk db -Ne "select DISTINCT h.php_handler_id from domains d join hosting h on h.dom_id=d.id WHERE d.name = '${domain}';")
# extract longer form php number from $php_handler_id, eg plesk-php82-fpm --> 82
readonly current_php_handler_id_number=$(echo "${php_handler_id}" | grep -oP '(?<=php)(.*)(?=-fpm)')
# multiply target_php_version by 10 to get the minimum php version id number, eg 8 * 10 = 80
readonly target_php_version_min_id_number=$((target_php_version * 10))

# if current_php_handler_id_number is less than the target_php_version_min_id_number
if [ "${current_php_handler_id_number}" -lt "${target_php_version_min_id_number}" ]
then
    # get the latest installed target_php_version, eg 82 (8.2)
    readonly latest_php_handler_id=$(plesk db -Ne "SELECT name FROM ServiceNodeEnvironment WHERE section = 'phphandlers' AND name REGEXP '^plesk-php${target_php_version}[0-9]+-fpm\$' ORDER BY ServiceNodeEnvironment.name DESC LIMIT 1;");

    # if latest_php_handler_id is not empty and is greater than or equal to the target_php_version_min_id_number
    if [ -n "${latest_php_handler_id}" ] && [ "${latest_php_handler_id}" -ge "${target_php_version_min_id_number}" ]
    then
        # update the domain to use the latest php version
        plesk bin site -u "${domain}" -php_handler_id "${latest_php_handler_id}"
        # run a series of plesk repair commands which all seem to be needed to get the domain working again (see https://talk.plesk.com/threads/503-error-after-changing-php_handler_id-for-site.370625/)
        plesk bin site --update-php-settings "${domain}"
        plesk repair web -php-handlers -php-fpm-configuration -y "${domain}"
        plesk bin domain --update-web-server-settings "${domain}"
    fi
fi
 
Back
Top