{"id":57769,"date":"2020-10-15T14:35:10","date_gmt":"2020-10-15T19:35:10","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=57769"},"modified":"2020-10-15T14:35:10","modified_gmt":"2020-10-15T19:35:10","slug":"how-to-use-php-fpm-with-cpanel","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/tips-and-tricks\/how-to-use-php-fpm-with-cpanel\/","title":{"rendered":"How to Use PHP-FPM with cPanel"},"content":{"rendered":"\n
PHP performance is an enduring issue for web hosts. PHP is the most widely used server programming language on the web by a big margin. The most popular content management systems and ecommerce applications are written in PHP, including WordPress\u00ae, Joomla, Drupal, Magento\u00ae, and dozens more. <\/p>\n\n\n\n
The ultra-fast PHP-FPM accelerates PHP execution on busy web servers, making it a valuable tool in the fight against slow sites and resource-constrained servers. <\/p>\n\n\n\n
This article takes a deep dive into how PHP-FPM works and explains how to deploy and configure it with cPanel & WHM. <\/p>\n\n\n\n
PHP-FPM is an alternative PHP implementation that makes busy web applications faster while helping system administrators to control resource consumption on their server. <\/p>\n\n\n\n
A PHP implementation, also known as the runtime, interprets and executes code. Traditional runtimes such as Apache\u2019s mod_PHP do their work within the web server. That approach has advantages, but each connection consumes a chunk of the server\u2019s resources for as long as it lasts. If there are too many concurrent connections, the server may run out of resources like memory altogether, impacting the performance of every site it hosts. <\/p>\n\n\n\n
PHP-FPM does things differently: it operates outside of the web server and uses a pool of worker processes to execute code. The workers are ready and waiting when a request comes in, and you can control how many workers are in the pool so they can\u2019t multiply until they consume all the server\u2019s RAM and processor time. <\/p>\n\n\n\n
It works like this:<\/p>\n\n\n\n If there are too many concurrent connections, some might have to wait for a free worker, but they will never consume all of the server\u2019s resources. On a busy web server, worker pools are faster and more efficient than other strategies. <\/p>\n\n\n\n It is straightforward to activate and configure PHP-FPM in cPanel & WHM. You can choose which domains use it and set configuration variables that influence its behavior. <\/p>\n\n\n\n The first step is to turn it on in the System PHP-FPM <\/em>settings in WHM\u2019s MutliPHP Manager. <\/em><\/p>\n\n\n\n When you click Turn On<\/em>, WHM makes PHP-FPM available, but it doesn\u2019t activate it for all domains automatically. You can force all accounts on the server to use PHP-FPM by clicking Convert All Accounts to PHP-FPM. <\/em><\/p>\n\n\n\n Alternatively, you can activate PHP-FPM for individual domains in the table at the bottom of this page. To turn it on for several domains at once, select them in the table and choose On <\/em>in the drop-down menu. <\/p>\n\n\n\n Once you have activated PHP-FPM, you can configure both the system defaults and the settings for individual domains in MultiPHP Manager. <\/em><\/p>\n\n\n\n Click the System PHP-FPM Configuration <\/em>tab. <\/p>\n\n\n\n In this section, there are three pool settings you can change. These are the default values that are applied to domain pools. <\/p>\n\n\n\n Many factors affect the optimal values for these settings, including the code your server runs and the amount of RAM it has. We wrote PHP-FPM Performance Tuning Basics<\/em><\/a> <\/em>to help you decide on the correct values for your server. <\/p>\n\n\n\n Underneath the pool options are PHP INI directives. We surface several of the most useful in the interface, and you can find more information about them in PHP\u2019s Runtime Configuration<\/em> documentation<\/a>. We\u2019ll show you how to add other directives in the next section. <\/p>\n\n\n\n In addition to system-wide configuration, you can also configure individual domains in the WHM interface. <\/p>\n\n\n\n In the table at the bottom of MutliPHP Manager, <\/em>click Edit PHP-FPM<\/em> at the end of the domain\u2019s row. The options that appear are identical to those in the system-wide configuration interface. <\/p>\n\n\n\n Although the WHM interface contains the most useful configuration options, there are many more in the documentation<\/a>. To add or modify them, you will need to edit configuration files on the server\u2019s command line<\/a> or in the cPanel & WHM File Manager. <\/em><\/p>\n\n\n\n The two most important system-wide configuration files are:<\/p>\n\n\n\n WHM doesn\u2019t create these files because the system doesn\u2019t need them, but you can create them yourself and add directives to override the defaults. <\/p>\n\n\n\n You may also have to create the directory with:<\/p>\n\n\n\n In these files, enter only directives that differ from and override the system directives. For example, if you wanted to change the emergency_restart_threshold <\/em>directive from the default of 0, the system_pool_defaults.yaml <\/em>file would look like this:<\/p>\n\n\n\n The three dashes at the top of the file (\u2014\u2014\u2014) are part of the YAML markup language and must be present. The configuration file won\u2019t work without them. <\/p>\n\n\n\n In the PHP documentation, you will find directives formatted with periods (.) and other symbols; syslog.facility<\/em>, <\/em>for example. When adding directives to configuration files, these symbols must be replaced with an underscore (_). For example, instead of syslog.facility, <\/em>use syslog_facility. <\/em><\/p>\n\n\n\n You can learn more about configuring the cPanel PHP-FPM module in Configuration Values of PHP-FPM<\/a> and PHP-FPM Code and FileSystem Layout for EasyApache 4<\/a>. <\/p>\n\n\n\n Finally, we\u2019ll look at manually creating and configuring domain-specific user pools in PHP-FPM. These are the worker pools used by sites hosted on your server\u2019s domains. <\/p>\n\n\n\n The PHP-FPM module creates a worker pool for a domain if it finds a configuration file in:<\/p>\n\n\n\n Replace [user] and [domain] with the relevant values for your server. You can create this file or activate PHP-FPM for a domain in WHM and it will be created automatically. <\/p>\n\n\n\n At a minimum, the file must<\/strong> contain the following information:<\/p>\n\n\n\n As with the system files, you can add directives to configure the user pools. After creating or editing the .yaml file, run the following command:<\/p>\n\n\n\n The script adds directives to Apache\u2019s config file and restarts PHP-FPM, after which the new pool will be up and running. You can find more information about creating user pools in PHP-FPM User Pools<\/a>.<\/p>\n\n\n\n PHP-FPM gives busy web servers a huge performance boost. Just as important, it helps web hosts to make the most of limited server resources, reducing the cost of providing an excellent hosting experience to clients and their users.<\/p>\n\n\n\n With cPanel & WHM, PHP-FPM can be activated in seconds and configured in an intuitive interface. If you need to dig deeper into PHP directives, our module makes building custom configurations for the runtime and worker pools straightforward. <\/p>\n\n\n\n As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You\u2019ll find us on Discord<\/a>, the cPanel forums<\/a>, and Reddit<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" PHP performance is an enduring issue for web hosts. PHP is the most widely used server programming language on the web by a big margin. The most popular content management systems and ecommerce applications are written in PHP, including WordPress\u00ae, Joomla, Drupal, Magento\u00ae, and dozens more. The ultra-fast PHP-FPM accelerates PHP execution on busy web […]<\/p>\n","protected":false},"author":77,"featured_media":65549,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[61],"tags":[],"class_list":["post-57769","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks"],"acf":[],"yoast_head":"\n<\/figure>\n\n\n\n
Getting Started with PHP-FPM in CentOS and EasyApache<\/strong><\/h2>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Configuring PHP-FPM in cPanel<\/strong><\/h2>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
How the cPanel PHP-FPM Module Works<\/strong><\/h2>\n\n\n\n
touch \/var\/cpanel\/ApachePHPFPM\/system.yaml\ntouch \/var\/cpanel\/ApachePHPFPM\/system_pool_defaults.yaml<\/code><\/pre>\n\n\n\n
mkdir -p \/var\/cpanel\/ApachePHPFPM\/<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
Creating User Pools in PHP-FPM<\/strong><\/h2>\n\n\n\n
\/var\/cpanel\/userdata\/[user]\/[domain].php_fpm.yaml<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
\/scripts\/php_fpm_config --rebuild\n<\/code><\/pre>\n\n\n\n
Easy PHP-FPM Configuration with cPanel & WHM<\/strong><\/h2>\n\n\n\n