概要: Plesk provides support for the PHP scripting language, including support for multiple PHP versions and handler types out of the box.

In this topic, you will learn how to manage PHP settings for domains in Plesk.

Plesk supports multiple PHP versions out of the box. You can configure individual domains to use different combination of PHP version and handler, and also configure additional PHP settings on a per-domain basis.

備註: You may only be able to manage some of the settings, or none at all, depending on your subscription settings. If you need to manage PHP settings that are unavailable to you, contact your hosting provider.

You can see the currently selected PHP version next to the PHP icon right on the domain card.

image php version

If there is no PHP version shown next to the PHP icon, PHP is not enabled for the domain.

image php disabled

Configuring the PHP Version and Handler Type

Selecting the PHP version and handler type for a domain

  1. 登錄到 Plesk

  2. Go to Websites & Domains, find the domain whose PHP version you want to change, and then click PHP.

  3. Select the 「PHP support」 checkbox if it is clear.

  4. Select the desired PHP version from the drop-down menu. If the desired PHP version is missing from the menu, contact your hosting provider.

    image php version selector

  5. Select the desired handler type from the drop-down menu.

    image php handler selector

  6. 點按 確定

The changes you made will take effect shortly.

備註: Different PHP versions are not 100% compatible. A website written in PHP 8.x may not function correctly if you configure a different PHP version for the domain. If you are not sure what PHP version to choose, use the default setting or the latest version available. If your website is not displaying correctly, try switching to a different PHP version.

備註: What PHP handler(s) are available for a domain depends on the selected PHP version and your Plesk server’s operating system. If you are not sure what PHP handler type to choose, learn about the different PHP handler types.

Using the Dedicated PHP-FPM Handler

專用 PHP-FPM 處理常式通過為每個網站運行獨立的PHP主進程,實現更高的穩定性和網站的隔離性。通過這種方式,每個網站都獨立於其他網站運行其腳本。也就是說網站的操作不影響其他網站的運行,在以下情況下不受影響:

  • 更改網站的 PHP 設定。
  • 更改網站的 PHP 處理常式。
  • 停止、重啟 PHP主進程或該主程序崩潰。
  • 網站的PHP腳本中出現錯誤。

When the dedicated PHP-FPM handler is turned on for a website, you can start, stop, or restart its PHP master process from the domain’s PHP page:

image control php master process

備註: Before selecting the dedicated PHP-FPM handler for a domain, take the following into account:

  • The handler only works with PHP version 7.3 or later.
  • 該處理常式增加了 OPcache 記憶體消耗。

配置其它的 PHP 設定

In addition to the PHP version and handler type, there are a number of PHP settings you can manage from a domain’s PHP page. These settings are mostly performance and security-related, but some of them may affect the operation of websites. Click the image question mark icon next to an option to learn more about it.

Configuring additional PHP settings for a domain

  1. 登錄到 Plesk
  2. Go to Websites & Domains, find the domain whose PHP settings you want to change, and then click PHP.
  3. Make the desired changes, and then click OK.

The changes you made will take effect shortly.

如果您的域名使用一個 「FPM 應用程式」 PHP 處理常式,您則可以配置其它的 PHP-FPM 設定。這些設定可用於調整PHP以優化網站性能。

這些設定的預設值對於大多數網站來說已最優配置。記住更改這些設定可能會影響您網站的性能或甚至會導致網站顯示異常。除非您確定要進行哪些更改,否則建議您為所有其它設定保留預設值。如果您對 PHP 設定進行了更改,導致您的網站變慢或停止載入,請恢復所有的 PHP 設定為預設值。

啟用 PHP 加速

如果您的主機提供商允許,您可能可以為您的網站啟用 PHP 加速,也就是通常所說的 opcode 緩存模組。如果您的網站是以 PHP 寫入的,啟用 opcode 緩存模組可以加速兩倍或更快。

Enabling PHP acceleration for a domain

  1. 登錄到 Plesk
  2. Go to Websites & Domains, find the domain you want to enable PHP acceleration for, and then click PHP.
  3. Set the value of opcache.enable to on, and then click OK.

The change will take effect shortly.

查看 PHP 設定

若要查看為您域名當前配置的 PHP 設定,包括伺服器級別的配置的設定,請點按 查看 phpinfo() 頁面

繼承 PHP 設定

屬於一個訂閱的域名會繼承域名級別定義的 PHP 設定。子域名會繼承其父系網域名級別定義的 PHP 設定。如果您的訂閱有相應的許可權,您則可以單獨為每個域名和子域名更改 PHP 設定。