{"id":804,"date":"2021-07-23T12:38:33","date_gmt":"2021-07-23T12:38:33","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/php-fpm-domain-pools\/"},"modified":"2021-07-23T12:38:33","modified_gmt":"2021-07-23T12:38:33","slug":"php-fpm-domain-pools","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/php-fpm-domain-pools\/","title":{"rendered":"PHP-FPM Domain Pools"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<p>This document explains how the system creates a domain pool with PHP-FPM.<\/p>\n<h2 id=\"how-does-the-system-create-pools\">How does the system create pools?<\/h2>\n<p>The system creates a pool when the <code>\/var\/cpanel\/userdata\/[user]\/[domain].php_fpm.yaml<\/code> configuration file exists in the domain. This file <strong>must<\/strong> include the following lines:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#f92672\">---<\/span>\n<span style=\"color:#a6e22e\">_is_present<\/span>: <span style=\"color:#ae81ff\">1<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<p>You may place any desired pool values in this file.<\/p>\n<ul>\n<li>You <strong>must<\/strong> include the <code>---<\/code> line above the pool values in this file.<\/li>\n<li>The <code>_is_present<\/code> value is optional, but you <strong>must<\/strong> include it if you do not set any other values in the file.<\/li>\n<\/ul>\n<div class=\"callout callout-danger\">\n<div class=\"callout-heading\">Warning:<\/div>\n<div class=\"callout-content\">\n        Exercise <strong>extreme<\/strong> caution when you manually edit <code>.yaml<\/code> files. Incorrect syntax in these files will cause services to fail. We <strong>strongly<\/strong> recommend that you create a backup of your system before you manually edit <code>.yaml<\/code> files.\n    <\/div>\n<\/div>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n        This file <strong>only<\/strong> contains the differences of directives from the built-in default directives.\n    <\/div>\n<\/div>\n<h3 id=\"create-a-pool\">Create a pool<\/h3>\n<p>To create a pool, run the <code>Cpanel::PHPFPM::rebuild_files()<\/code> function.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n        You may also run the <code>\/scripts\/php_fpm_config --rebuild<\/code> script to create a pool.\n    <\/div>\n<\/div>\n<p>The system will perform the following steps:<\/p>\n<ul>\n<li>\n<p>The system scans for the <code>\/var\/cpanel\/ApachePHPFPM\/system.yaml<\/code> and <code>\/var\/cpanel\/ApachePHPFPM\/system_pool_defaults.yaml<\/code> files and then generates a system configuration for each of the PHP versions.<\/p>\n<\/li>\n<li>\n<p>The system searches for the domain\u2019s <code>yaml<\/code> files.<\/p>\n<\/li>\n<li>\n<p>The system generates a line in the <code>\/opt\/cpanel\/[ea_php_version]\/root\/etc\/php-fpm.d\/[domain].conf<\/code> file for every <code>domain.yaml<\/code> file.<\/p>\n<\/li>\n<li>\n<p>To direct the requests to the <code>php_fpm<\/code> daemon with Apache, the system modifies the <code>httpd.conf<\/code> file with the <code>rebuild_files()<\/code> script to resemble the following example:<\/p>\n<\/li>\n<\/ul>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-php\" data-lang=\"php\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-php\" data-lang=\"php\"># php -- BEGIN cPanel-generated handler, do not edit\n&lt;<span style=\"color:#f92672\">FilesMatch<\/span> <span style=\"color:#960050;background-color:#1e0010\">\".(<\/span><span style=\"color:#a6e22e\">phtml<\/span><span style=\"color:#960050;background-color:#1e0010\">|<\/span><span style=\"color:#a6e22e\">php<\/span><span style=\"color:#960050;background-color:#1e0010\">[<\/span><span style=\"color:#a6e22e\">0-9<\/span><span style=\"color:#960050;background-color:#1e0010\">]*)$\"<\/span>&gt;\n    SetHandler \"proxy:unix:\/home\/cptest3\/cptest3_tld.php_fpm.sock|fcgi:\/\/cptest3.tld\/\"\n&lt;\/<span style=\"color:#f92672\">FilesMatch<\/span>&gt;\n# php -- END cPanel-generated handler, do not edit<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>The system removes any existing <code>conf<\/code> files that do not contain a corresponding <code>domain.yaml<\/code> file.<\/p>\n<\/p><\/div>\n<\/div>\n<p>The system creates the FPM socket in the <code>\/opt\/cpanel\/phpversion\/root\/usr\/var\/run\/php-fpm\/obscure_domain.sock<\/code> directory, where <code>phpversion<\/code> represents the version of PHP, and <code>obscure_domain<\/code> represents a hashed version of the domain. Your hashed version will resemble the following example:<\/p>\n<pre><code>\/opt\/cpanel\/ea-php56\/root\/usr\/var\/run\/php-fpm\/4cfb2f15c04ae8a6a980ad6b78a834e7c8661958.sock\n<\/code><\/pre>\n<p>When the pool and system configurations exist in their designated locations, the system restarts the pools. The method that the system uses to restart them depends on whether it runs as a <code>systemd<\/code> or an <code>init.d<\/code> system. The system then removes any PHP version pools that do <strong>not<\/strong> hold domains with that version.<\/p>\n<h2 id=\"jail-shell\">Jail shell<\/h2>\n<p>When you create a PHP-FPM domain pool, if the following conditions exist, the system automatically binds them to the <code>virtfs<\/code> mount:<\/p>\n<ul>\n<li>The <code>\/var\/cpanel\/feature_toggles\/apachefpmjail<\/code> file exists.<\/li>\n<li>The WHM account uses either the <code>jailshell<\/code> or <code>noshell<\/code> settings.<\/li>\n<li>You enabled the _Experimental: Jail Apache Virtual Hosts using mod<em>ruid2 and cPanel\u00ae jailshell<\/em> setting in the <em>Security<\/em> section of WHM\u2019s  <em>Tweak Settings<\/em>  interface (<em>WHM &gt;&gt; Home &gt;&gt; Server Configuration &gt;&gt; Tweak Settings<\/em>).<\/li>\n<\/ul><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview This document explains how the system creates a domain pool with PHP-FPM. How does the system create pools? The system creates a pool when the \/var\/cpanel\/userdata\/[user]\/[domain].php_fpm.yaml configuration file exists in the domain. This file must include the following lines: 1 2 &#8212; _is_present: 1 You may place any desired pool values in this file. &hellip;<\/p>\n","protected":false},"author":1,"featured_media":805,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/804"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=804"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/804\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/805"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}