PHP设置
概要: 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.
If there is no PHP version shown next to the PHP icon, PHP is not enabled for the domain.
Configuring the PHP Version and Handler Type
Selecting the PHP version and handler type for a domain
-
Go to Websites & Domains, find the domain whose PHP version you want to change, and then click PHP.
-
Select the “PHP support” checkbox if it is clear.
-
Select the desired PHP version from the drop-down menu. If the desired PHP version is missing from the menu, contact your hosting provider.
-
Select the desired handler type from the drop-down menu.
-
点击 确定 。
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:
注解: 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 icon next to an option to learn more about it.
Configuring additional PHP settings for a domain
- 登录到 Plesk。
- Go to Websites & Domains, find the domain whose PHP settings you want to change, and then click PHP.
- 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
- 登录到 Plesk。
- Go to Websites & Domains, find the domain you want to enable PHP acceleration for, and then click PHP.
- Set the value of
opcache.enable
toon
, and then click OK.
The change will take effect shortly.
查看 PHP 设置
若要查看为您域名当前配置的 PHP 设置,包括服务器级别的配置的设置,请点击 查看 phpinfo() 页面 。
继承 PHP 设置
属于一个订阅的域名会继承域名级别定义的 PHP 设置。子域名会继承其父域名级别定义的 PHP 设置。如果您的订阅有相应的权限,您则可以单独为每个域名和子域名更改 PHP 设置。