Articles in this section

How to change PHP version / handler for a domain or all domains in Plesk

Plesk for Windows kb: how-to Plesk for Linux ABT: Group A

Applicable to:

  • Plesk for Linux
  • Plesk for Windows

Question

How to change PHP version / handler for a domain or all domains?

Answer

 

For a domain

 

  1. Log in to Plesk.

  2. Go to Domains > example.com > PHP Settings.

  3. Select required PHP version and/or PHP handler from the drop-down list.

  4. Apply the changes.



For selected/all domains in Plesk for Linux

 

  1. Connect to the Plesk server via SSH.

  2. Generate a file with all domains:

    # plesk bin site --list > domains.txt

  3. (Optional) Open the file in a text editor and remove those domains that should not have their PHP version/handler changed.

  4. List all installed PHP handlers:

    # plesk bin php_handler --list

  5. Change PHP version/handler for the domains listed in domains.txt file using the command below:

    Note: Replace <php_handler> with <id> of a PHP handler from step 4.

    # cat domains.txt | while read i; do echo "[+] Updating domain: $i"; plesk bin domain -u $i -php_handler_id <php_handler>; done

    In the example below, the command will assign Plesk PHP 8.3 served by PHP-FPM:

    # cat domains.txt | while read i; do echo "[+] Updating domain: $i"; plesk bin domain -u $i -php_handler_id plesk-php83-fpm; done

     

To change the PHP version for all domains that use a specific PHP version, follow these steps:

  1. Create a list with the names of all domains that use a particular PHP version (in this example, PHP 7.4 FastCGI):

    # plesk db -sNe "select name from hosting h,domains dom where dom.id = h.dom_id and php = 'true' AND php_handler_id LIKE 'plesk-php74-cgi'" > domains.txt

  2. Switch these domains to another PHP version (in this example, PHP 8.3 FastCGI):

    # cat domains.txt | while read i; do echo "[+] Updating domain: $i"; plesk bin domain -u $i -php_handler_id plesk-php83-fpm; done

 

For selected/all domains in Plesk for Windows Server

 

  1. Connect to the Plesk server via RDP.

  2. Start a command prompt as an Administrator.

  3. Generate a file with all domains:

    C:\> plesk bin site --list > C:\domains.txt

  4. (Optional) Open the file in a text editor and remove those domains that should not have their PHP version/handler changed.

  5. List all installed PHP handlers:

    # plesk bin php_handler --list

  6. Change PHP version/handler for the domains listed in domains.txt file using the command below:

    Note: Replace <php_handler> with <id> of a PHP handler from step 5.

    C:\> for /f "tokens=*" %d in ('type C:\domains.txt') do plesk bin domain -u %d -php_handler_id <php_handler>

    In the example below, the command will assign Plesk PHP 8.3:

    # for /f "tokens=*" %d in ('type C:\domains.txt') do plesk bin domain -u %d -php_handler_id fastcgi-8.3

 

To change PHP version / handler for all domains that use a specific PHP version, follow these steps:

  1. Create a list with the names of all domains that use a particular PHP version (in this example, PHP 5.6 FastCGI):

    C:\> plesk db -sNe "select name from hosting hos,domains dom where dom.id = hos.dom_id and php = 'true' AND php_handler_id LIKE 'fastcgi-5.6'" > C:\domains.txt

  2. Switch these domains to another PHP version (in this example, PHP 8.3 FastCGI):

    C:\> for /f "tokens=*" %d in ('type C:\domains.txt') do plesk bin domain -u %d -php_handler_id fastcgi-8.3

Was this article helpful?

Comments

2 comments
Date Votes

Please sign in to leave a comment.