Question
How to configure the PHP-FPM plugin of 360 Monitoring on a Plesk server?
Answer
Note: All domains with the PHP-FPM plugin enabled must:
- have a valid SSL certificate
- be accessible (i.e. have correct DNS records, not blocked by a firewall, etc.)
The corresponding User Story (EXTPLESK-3359) was created to consider the future possibility of the automatic implementation of the plugin.
-
Go to Domains > example.com > PHP Settings
-
Add the following lines to the Additional directives field:
CONFIG_TEXT: [php-fpm-pool-settings]
pm.status_path = /status_phpfpm -
Click OK
-
Go to Domains > example.com > Apache & nginx Settings
-
Add the following lines to the Additional directives for nginx:
CONFIG_TEXT: location ~ ^/status_phpfpm$ {
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:///var/www/vhosts/system/example.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf;
} -
Click OK
-
Connect to the server via SSH
-
Add the following section to the file
/etc/agent360.ini
:CONFIG_TEXT: [phpfpm]
enabled = yes
status_page_url = https://example.com/status_phpfpm?json -
Restart the service:
# systemctl restart agent360
Note: It is needed to repeat the steps for every domain that is needed to be monitored. For multiple domains, the section in /etc/agent360.ini
should look like this one:
CONFIG_TEXT: [phpfpm]
enabled = yes
status_page_url = https://example.com/status_phpfpm?json, https://domain.tld/status_phpfpm?json, ...
-
Go to Domains > example.com > PHP Settings
-
Add the following lines to the Additional directives field:
CONFIG_TEXT: [php-fpm-pool-settings]
pm.status_path = /status_phpfpm -
Click OK
-
Go to Domains > example.com > Apache & nginx Settings
-
Add the following lines to the Additional directives for HTTPS:
CONFIG_TEXT: <LocationMatch "/status_phpfpm">
ProxyPass unix:///var/www/vhosts/system/example.com/php-fpm.sock|fcgi://127.0.0.1:9000
</LocationMatch> -
Click OK
-
Connect to the server via SSH
-
Add the following section to the file
/etc/agent360.ini
:CONFIG_TEXT: [phpfpm]
enabled = yes
status_page_url = https://example.com/status_phpfpm?json -
Restart the service:
# systemctl restart agent360
Note: It is needed to repeat the steps for every domain that is needed to be monitored. For multiple domains, the section in /etc/agent360.ini
should look like this one:
CONFIG_TEXT: [phpfpm]
enabled = yes
status_page_url = https://example.com/status_phpfpm?json, https://domain.tld/status_phpfpm?json, ...
Warning: Changes in the templates might result in incorrect work of all domains. The operations below should be handled by a Linux administrator.
-
Connect to the server via SSH
-
Copy the default template to create a custom one:
# cp -a /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
-
Edit file
/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
by adding the following lines:CONFIG_TEXT: location ~ ^/status_phpfpm$ {
allow <?php echo $OPT['ipAddress']->escapedAddress; ?>;
deny all;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix://<?php echo $VAR->server->webserver->vhostsDir ?>/system/<?php echo $VAR->domain->targetName; ?>/php-fpm.sock";
include /etc/nginx/fastcgi.conf;
}Note: The lines should be added as the last
location
section inside the block:CONFIG_TEXT: <?php if ($VAR->domain->active && $VAR->domain->physicalHosting->php && $VAR->domain->physicalHosting->proxySettings['nginxServePhp']): ?>
...
<?php endif ?> -
Update the PHP Settings by adding the necessary Additional directive:
# echo -e "[php-fpm-pool-settings]\npm.status_path = /status_phpfpm" > tmpfile && for domain in $(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -uadmin -Nse "SELECT name FROM psa.domains WHERE htype = 'vrt_hst'"); do plesk bin site --update-php-settings $domain -additional-settings tmpfile; done && rm -f tmpfile
-
Adjust the 360 Monitoring agent settings:
# plesk db -Nse "SELECT domains.name, WebServerSettingsParameters.value FROM hosting JOIN domains ON domains.id = hosting.dom_id JOIN WebServerSettingsParameters ON WebServerSettingsParameters.webServerSettingsId = (SELECT val FROM dom_param WHERE param = 'webServerSettingsId' AND dom_id = domains.id) WHERE WebServerSettingsParameters.name = 'nginxServePhp'" > domains_php.txt && echo -en "[phpfpm]\nenabled = yes\nstatus_page_url =" > tmpconffile && while read f; do if [ "$(echo $f | awk '{print $2}')" == "true" ]; then echo -n " https://$(echo $f | awk '{print $1}')/status_phpfpm?json," >> tmpconffile; fi; done < domains_php.txt && sed -i '$ s/.$//' tmpconffile && sed -i -e '$a' /etc/agent360.ini && cat tmpconffile >> /etc/agent360.ini && rm -f tmpconffile domains_php.txt
-
Apply the web configuration:
# plesk repair web -y
-
Restart the agent:
# systemctl restart agent360
-
Connect to the server via SSH
-
Copy the default template to create a custom one:
# cp -a /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php
-
Edit file
/usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php
by adding the following lines:CONFIG_TEXT: <LocationMatch "/status_phpfpm">
Require ip <?php echo $OPT['ipAddress']->escapedAddress; ?> 127.0.0.1 ::1
ProxyPass unix://<?php echo $VAR->server->webserver->vhostsDir ?>/system/<?php echo $VAR->domain->targetName; ?>/php-fpm.sock|fcgi://127.0.0.1:9000
</LocationMatch>Note: The lines should be added after the section below:
CONFIG_TEXT: <?php if ($OPT['ssl'] || !$VAR->domain->physicalHosting->ssl): ?>
Alias "/plesk-stat" "<?php echo $VAR->domain->physicalHosting->statisticsDir ?>"
...
Redirect permanent /awstats-icon https://<?php echo $VAR->domain->urlName ?>/awstats-icon
<?php endif; ?>
<?php endif; ?> -
Update the PHP Settings by adding the necessary Additional directive:
# echo -e "[php-fpm-pool-settings]\npm.status_path = /status_phpfpm" > tmpfile && for domain in $(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -uadmin -Nse "SELECT name FROM psa.domains WHERE htype = 'vrt_hst'"); do plesk bin site --update-php-settings $domain -additional-settings tmpfile; done && rm -f tmpfile
-
Adjust the 360 Monitoring agent settings:
# plesk db -Nse "SELECT domains.name, WebServerSettingsParameters.value FROM hosting JOIN domains ON domains.id = hosting.dom_id JOIN WebServerSettingsParameters ON WebServerSettingsParameters.webServerSettingsId = (SELECT val FROM dom_param WHERE param = 'webServerSettingsId' AND dom_id = domains.id) WHERE WebServerSettingsParameters.name = 'nginxServePhp'" > domains_php.txt && echo -en "[phpfpm]\nenabled = yes\nstatus_page_url =" > tmpconffile && while read f; do if [ "$(echo $f | awk '{print $2}')" == "false" ]; then echo -n " https://$(echo $f | awk '{print $1}')/status_phpfpm?json," >> tmpconffile; fi; done < domains_php.txt && sed -i '$ s/.$//' tmpconffile && sed -i -e '$a' /etc/agent360.ini && cat tmpconffile >> /etc/agent360.ini && rm -f tmpconffile domains_php.txt
-
Apply the web configuration:
# plesk repair web -y
-
Restart the agent:
# systemctl restart agent360
Note: If it is supposed to use both domains on Apache and domains on Nginx, execute the commands from steps 4, 5, and 7 just once. The command from step 6 should be replaced with the following one (executed once as well):
# echo -en "[phpfpm]\nenabled = yes\nstatus_page_url =" > tmpconffile && for domain in $(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -uadmin -Nse "SELECT name FROM psa.domains WHERE htype = 'vrt_hst'"); do echo -n " https://$domain/status_phpfpm?json," >> tmpconffile; done && sed -i '$ s/.$//' tmpconffile && cat tmpconffile >> /etc/agent360.ini && rm -f tmpconffile
-
Connect to the server via SSH
-
Download the script:
# curl -OL https://raw.githubusercontent.com/plesk/kb-scripts/master/360-phpfpm-plugin-conf/360-phpfpm-plugin-conf.py
-
Execute the script:
# python3 360-phpfpm-plugin-conf.py
-
Apply the web configuration:
# plesk repair web -y
Comments
0 comments
Please sign in to leave a comment.