Koozali.org: home of the SME Server

adding php.ini setting not covered by Webhosting or db accounts

Offline wdepot

  • ****
  • 95
  • +0/-0
    • http://westerndepot.com
adding php.ini setting not covered by Webhosting or db accounts
« on: December 05, 2024, 10:54:44 PM »
I've run into a situation where I need to change the php.ini setting for max_input_vars to a larger number to accommodate a PHP program that can create a form with a few thousand checkbox inputs. Unfortunately this particular setting is not covered by Webhosting (not surprising since most people wouldn't need more than the default 1000 input variables) nor is it one you can set with db accounts setprop.

Based on information found in another post it looks like I need to create a custom template for php-fpm.d/ibays.conf named to come after the 10Ibays file so I'm choosing the file name ZZcustom to be safe. Since the example shown by the PHP documentation I was pointed to seem to be for creating a new pool rather than adding a setting to an existing pool I thought it might be best to base the custom template on the 10Ibays file so I came up with the following:
Code: [Select]
{

use esmith::AccountsDB;
use esmith::php;
my $a = esmith::AccountsDB->open_ro || die "Couldn't open the accounts database";

foreach my $ibay ($a->get_all_by_prop(type => 'ibay')){
  my $version   = PhpFpmVersionToUse($ibay);

  $OUT .=<<"_EOF" if ($version eq $PHP_VERSION);

[$pool_name]
php_admin_value[max_input_vars] = 5000

_EOF
}

}

I just wanted to be sure that this will ADD this to the other settings for the pool and not replace them.

Offline ReetP

  • *
  • 3,884
  • +5/-0
Re: adding php.ini setting not covered by Webhosting or db accounts
« Reply #1 on: December 06, 2024, 01:42:01 PM »
I think you probably should know by now that creating a custom template with the same name as an existing one will overwrite everything from the original one. As per the documentation.

You need a custom template with  a modification to the original.

( Also see https://bugs.koozali.org/show_bug.cgi?id=12302 )

Here is my modified version with several new variables:

diff -ruN /etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays /etc/e-smith/templates-custom/etc/php-fpm.d/ibays.conf/10Ibays


Code: [Select]
--- /etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays 2024-03-20 12:17:01.000000000 +0100
+++ /etc/e-smith/templates-custom/etc/php-fpm.d/ibays.conf/10Ibays 2024-03-21 14:57:44.711814703 +0100
@@ -38,6 +38,19 @@
   $error_reporting    = ($error_reporting eq 'E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT') ? '; default error_reporting' : "php_value[error_reporting] = $error_reporting";
   $open_basedir       = join(':',  split(/[,;:]/, $open_basedir .  $autoprepath));
 
+# Custom vars
+  my $max_input_vars      = (defined $ibay->prop('MaxInputVars'))? $ibay->prop('MaxInputVars') : $defaultPHPproperties{'MaxInputVars'} || '1000';
+  my $short_open_tag      = (defined $ibay->prop('ShortOpenTag'))? $ibay->prop('ShortOpenTag') : $defaultPHPproperties{'ShortOpenTag'} || 'On';
+  my $sessionProb         = (defined $ibay->prop('SessionProbability'))? $ibay->prop('SessionProbability') : $defaultPHPproperties{'SessionProbability'} || '1';
+  my $max_children        = (defined $ibay->prop('PHPmaxChildren'))? $ibay->prop('PHPmaxChildren') : $defaultPHPproperties{'PHPmaxChildren'} || 20;
+  my $min_spare_servers   = (defined $ibay->prop('PHPminServers'))? $ibay->prop('PHPminServers') : $defaultPHPproperties{'PHPminServers'} || 4;
+  my $start_servers       = (defined $ibay->prop('PHPstartServers'))? $ibay->prop('PHPstartServers') : $defaultPHPproperties{'PHPstartServers'} || 6;
+  my $max_spare_servers   = (defined $ibay->prop('PHPmaxServers'))? $ibay->prop('PHPmaxServers') : $defaultPHPproperties{'PHPmaxServers'} || 8;
+  my $max_requests        = (defined $ibay->prop('PHPmaxRequests'))? $ibay->prop('PHPmaxRequests') : $defaultPHPproperties{'PHPmaxRequests'} || 1000;
+  $min_spare_servers      = ( $min_spare_servers > $max_spare_servers ) ? sprintf("%.0f", $max_spare_servers/2) : $min_spare_servers;
+  $start_servers          = ( $start_servers > $max_spare_servers ) ? sprintf("%.0f", $max_spare_servers/2 +  $min_spare_servers/2  ) : $start_servers;
+
+
   $OUT .=<<"_EOF" if ($version eq $PHP_VERSION);
 
 [$pool_name]
@@ -48,11 +61,11 @@
 listen.mode = 0660
 listen = /var/run/php-fpm/$pool_name.sock
 pm = dynamic
-pm.max_children = 15
-pm.start_servers = 3
-pm.min_spare_servers = 3
-pm.max_spare_servers = 4
-pm.max_requests = 1000
+pm.max_children = $max_children
+pm.start_servers = $start_servers
+pm.min_spare_servers = $min_spare_servers
+pm.max_spare_servers = $max_spare_servers
+pm.max_requests = $max_requests
 $limitExtensions
 slowlog = /var/log/php/$key/slow.log
 php_admin_value[session.save_path] = /var/lib/php/$key/session
@@ -78,6 +91,10 @@
 php_admin_value[auto_prepend_file] = $autoprep
 php_admin_value[open_basedir] = $open_basedir
 
+php_admin_value[max_input_vars] = $max_input_vars
+php_admin_value[short_open_tag] = $short_open_tag
+php_admin_value[session.gc_probability] = $sessionProb
+
 _EOF
 }



You can steal just the max_input_vars of you want:

Code: [Select]
+# Custom vars
+  my $max_input_vars      = (defined $ibay->prop('MaxInputVars'))? $ibay->prop('MaxInputVars') : $defaultPHPproperties{'MaxInputVars'} || '1000';
+php_admin_value[max_input_vars] = $max_input_vars

Also note that if you are competent enough to be hacking about with templates you are competent enough to be helping build v11 which does not build itself.

https://forums.koozali.org/index.php/topic,55236.msg291457.html#msg291457

(yes, we're all busy with life as well.....)
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline wdepot

  • ****
  • 95
  • +0/-0
    • http://westerndepot.com
Re: adding php.ini setting not covered by Webhosting or db accounts
« Reply #2 on: December 06, 2024, 10:49:11 PM »
I think you probably should know by now that creating a custom template with the same name as an existing one will overwrite everything from the original one. As per the documentation.

As I said in my question the file name for the custom template is ZZcustom and is intended to go in
/etc/e-smith/templates-custom/etc/php-fpm.d/ibays.conf/ZZcustom
which I purposely did to avoid conflict with 10Ibays.

What I wanted to know is will it create a problem since the resulting expanded template structure will look something like this?
Code: [Select]
[Primary]
default SME PHP settings
[other-ibays]
default SME PHP settings
[Primary]
custom max_input_vars setting
[other-ibays]
custom max_input_vars setting
I'm just wondering if having a second set of settings for each pool will add to the settings in the first set since they aren't duplicated or cause the first set to be ignored. I know in the regular php.ini if a specific setting is listed twice, the second one is the one that is effective. I don't know if this is true for pool groups for php-fpm.

I see from the link you gave that the plan for SME 11 is to split the 10Ibays file so that the end of loop is in a separate file to allow for custom template files to be put in the middle which would solve this issue instantly.

Offline ReetP

  • *
  • 3,884
  • +5/-0
Re: adding php.ini setting not covered by Webhosting or db accounts
« Reply #3 on: December 07, 2024, 12:29:12 AM »
I showed you how to do it. All the work is already done for you.

Set the key on the ibay and webapps-update and job done.

Not sure what else I can do.

You method will likely break stuff but by all means try it.

Bug 12302 shows different methods under consideration, but also that nothing is decided yet. Hence it is "Confirmed" and not "Resolved".

For now this method will suffice.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline wdepot

  • ****
  • 95
  • +0/-0
    • http://westerndepot.com
Re: adding php.ini setting not covered by Webhosting or db accounts
« Reply #4 on: December 07, 2024, 02:16:36 AM »
I feel silly now that I happened to check a test server with SME 10 and discovered that the max_input_vars was set higher than PHP default. It turns out that php-fpm apparently gets its base settings from /etc/php.ini and then overrides the settings that have been set to a different value using Webhosting with the values set by Webhosting.

The solution to my problem was as simple as creating a custom template for /etc/php.ini that is named so that it comes AFTER the SME templates (so anything that will come after 80ModuleSettings24Ldap) that contains the needed php.ini settings, then expand the template and restart the server.

Offline ReetP

  • *
  • 3,884
  • +5/-0
Re: adding php.ini setting not covered by Webhosting or db accounts
« Reply #5 on: December 07, 2024, 11:02:37 AM »
I'm not quite sure you understand how it all works.

Remember we though we use php, but we actually use php-fpm.

https://wiki.koozali.org/PHP

The solution I posted above is the correct one and allows you to set different values per ibay

Your version is essentially using a hammer to crack a nut and you should avoid using it because it can have other complications. You just don't understand enough to know.

Just do as I demonstrated and it works perfectly.

Code: [Select]
db accounts setprop <ibayname> MaxInputVars 9000
signal-event webapps-update

Yes my crm needs 9000.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation