I became aware of what an alternative configuration would do after reading an article titled A better way to run PHP-FPM. It was written about a year ago, so it’s kinda disappointing that I came across it while searching for a related topic just last night. If you run your own server and use PHP with PHP-FPM, you need to read that article.
After I read it, I changed the pm options in the pool configuration file to these:Updated pool PHP-FPM valuesShell
1234 ; Choose how the process manager will control the number of child processes.pm = ondemandpm.max_children = 75pm.process_idle_timeout = 10spm.max_requests = 500
The major change was setting pm = ondemand instead of pm = dynamic. And the impact on resource usage was drastic. Here, for example, is the output ofRelated Post: Eyes in the Sky: The Rise of Gorgon Stare and How It Will Watch Us All
free –mt after reloading php5-fpm:Output of `free -mt`Shell
1234 total used free shared buffers cachedMem: 490 196 293 28 9 70–/+ buffers/cache: 116 373Swap: 2047 452 1595Total: 2538 649 1888
Compared to the output before, that’s more than a 50% drop in RAM usage. And the reason became obvious when I viewed top again:Output of `top`
1234 2778 mysql 20 1359152 56708 3384 S 0.0 11.3 2:11.06 mysqld26896 root 20 373828 19000 13532 S 0.0 3.8 :02.42 php5–fpm 25818 root 20 64208 4148 1492 S 0.0 0.8 :01.88 php5–fpm25818 root 20 64208 4148 1492 S 0.0 0.8 :01.88 php5–fpm17385 root 20 64208 4068 1416 S 0.0 0.8 :02.23 php5–fpm 1465 ossec 20 15592 2960 480 S 0.0 0.6 :08.60 ossec–analysisd1500 root 20 6312 2072 328 S 0.0 0.4 :45.55 ossec–syscheckd 1 root 20 33444 1940 812 S 0.0 0.4 :03.29 init
Did you notice that there are no child processes? What happened to them? That’s what setting pm = ondemand does. A child process is spawned only when needed. After it’s done its job, it remains idle for 10 seconds (pm.process_idle_timeout = 10s) and then dies.
So what I have is a simple modification to the default PHP-FPM settings that saved me more than 50% of RAM. Sure, the server hasn’t come under heavy traffic, but I think it can withstand a reasonably heavy traffic, considering that it only has 512 MB of RAM. And with Nginx microcaching configured, I think it will do very well. There are other aspects of PHP-FPM and Percona MySQL that I’ve not optimized yet, so stay tuned. This was just to pass on a little tip that I found useful.
For the PHP installation we recommend to use Ondřej Surý‘s PPA, which provides latest PHP versions for Debian systems. Add this PPA to your Debian system using the following commands:wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add - sudo echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list
After that, install the required PHP version. You can simply execute the following commands for the default PHP version installation with PHP-FPM packages.apt update sudo apt install php php-fpmNote:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.3/fpm/ directory. You can read more about enable/disable PHP modules.
After installing the above packages php7.3-fpm service will automatically be started. You can make sure by typing below command on terminal.sudo systemctl status php7.3-fpm ● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-12-03 10:01:54 UTC; 24min ago Docs: man:php-fpm7.3(8) Main PID: 9883 (php-fpm7.3) Status: "Processes active: 0, idle: 2, Requests: 3, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 3587) Memory: 14.2M CGroup: /system.slice/php7.3-fpm.service ├─9883 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf) ├─9884 php-fpm: pool www └─9885 php-fpm: pool wwwDec 03 10:01:54 tecadmin-debian10 systemd: Starting The PHP 7.3 FastCGI Process Manager... Dec 03 10:01:54 tecadmin-debian10 systemd: Started The PHP 7.3 FastCGI Process Manager.
It also packages the Bitnami MariaDB chart which is required for bootstrapping a MariaDB deployment for the database requirements of the WordPress application.
Bitnami charts can be used with Kubeapps for deployment and management of Helm Charts in clusters. This chart has been tested to work with NGINX Ingress, cert-manager, fluentd and Prometheus on top of the BKPR.
For performance and security reasons, it is a good practice to configure Apache with
AllowOverride None. Instead of using
.htaccessfiles, Apache will load the same dircetives at boot time. These directives are located in
/opt/bitnami/wordpress/wordpress-htaccess.conf. The container image includes by default these directives all of the default
.htaccessfiles in WordPress (together with the default plugins). To enable this feature, install the chart with the following value:
helm install stable/wordpress --set allowOverrideNone=yes
However, some plugins may include
.htaccessdirectives that will not be loaded when
AllowOverrideis set to
None. A way to make them work would be to create your own
wordpress-htaccess.conffile with all the required dircectives to make the plugin work. After creating it, then create a ConfigMap with it.
kubectl create cm custom-htaccess --from-file=/path/to/wordpress-htaccess.conf
Then, install the chart:
helm install stable/wordpress --set allowOverrideNone=yes --set customHTAccessCM=custom-htaccess