简体   繁体   English

如何永久增加 max_input_vars? php.ini 方法会定期被覆盖

[英]How can I permanently increase max_input_vars? The php.ini approach periodically gets overridden

I manage a VPS, where I would like to increase the max_input_vars for one of the WordPress sites that is hosted on the VPS.我管理一个 VPS,我想为 VPS 上max_input_vars的其中一个 WordPress 站点增加max_input_vars To do this, I headed over to /var/www/vhosts/system/example.com/etc/ and entered the following into the enclosed php.ini file:为此,我前往/var/www/vhosts/system/example.com/etc/并在随附的php.ini文件中输入以下内容:

max_input_vars =4000

Whilst this worked, the file gets overridden periodically and thus I lose my modification.虽然这有效,但该文件会定期被覆盖,因此我丢失了我的修改。

Is there an alternative way to achieve this modification, without the worry of the php.ini being automatically overridden?有没有其他方法可以实现这种修改,而不必担心php.ini被自动覆盖?

I have tried the following but all have resulted in the website being taken offline:我尝试了以下方法,但都导致网站脱机:

.htaccess .htaccess

php_value max_input_vars 4000

wp-config配置文件

@ini_set( 'max_input_vars' , 4000 );

Update: 09/01/2020更新:09/01/2020

I have also tried entering php_admin_flag max_input_vars On into the /etc/apache2/apache2.conf file followed by entering max_input_vars =4000 into the /var/www/vhosts/system/example.com/etc/php.ini file.我还尝试将php_admin_flag max_input_vars On输入到/etc/apache2/apache2.conf文件中,然后将max_input_vars =4000输入到/var/www/vhosts/system/example.com/etc/php.ini文件中。

Unfortunately, the max_input_vars =4000 still gets overridden with the default of 1000 being reset.不幸的是, max_input_vars =4000仍然会被重置为默认值 1000。 Furthermore, this approach produces the following notifications;此外,这种方法会产生以下通知; within the server:服务器内:

在此处输入图片说明

Could I be doing something wrong here?我在这里做错了吗?

So,max_input_vars is PHP_INI_PERDIR which means it can be set in either php.ini, .htaccess, httpd.conf or .user.ini ( since PHP 5.3 ).因此,max_input_varsPHP_INI_PERDIR ,这意味着它可以在 php.ini、.htaccess、httpd.conf 或 .user.ini 中设置(自 PHP 5.3 起)。

PHP only has one solution for preventing local directive overrides ( local directives override master directives in PHP so it bubbles from the bottom up ) and that's to set an admin_flag on the directive, thus preventing the master configuration from being override locally. PHP 只有一种防止本地指令覆盖的解决方案(本地指令覆盖 PHP 中的主指令,因此它自下而上冒泡),那就是在指令上设置一个admin_flag ,从而防止主配置被本地覆盖。 To do this it will depend on which PHP SAPI you're using.为此,这将取决于您使用的 PHP SAPI。

mod_php (Apache httpd) mod_php (Apache httpd)

You can set php_admin_flag in your apache config (ie virtualhost file or httpd.conf) using php_admin_flag max_input_vars On in your httpd config.您可以设置php_admin_flag使用Apache配置(即虚拟主机的文件或httpd.conf文件) php_admin_flag max_input_vars On你的httpd配置。 This will prevent the loaded value from your php.ini to be overridden by .htaccess or ini_set() .这将防止 php.ini 中加载的值被 .htaccess 或ini_set()覆盖。

php-fpm (fastcgi) php-fpm (fastcgi)

You can set the php_admin_flag in your php-fpm config or individual pool configs with the syntax php_admin_flag[max_input_vars] = On .您可以设置php_admin_flag在你的PHP-FPM配置或语法个别池CONFIGS php_admin_flag[max_input_vars] = On

NB NB

However, before proceeding please take under advisement the importance of not setting this directive too high as it can cause a known Denial of Service attack in PHP.但是,在继续之前,请注意不要将此指令设置得太高,因为它可能会导致 PHP 中已知的拒绝服务攻击。 From the manual...从手册...

Use of this directive mitigates the possibility of denial of service attacks which use hash collisions.使用此指令可以减少使用哈希冲突的拒绝服务攻击的可能性。 If there are more input variables than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.如果输入变量多于此指令指定的数量,则会发出E_WARNING ,并从请求中截断更多输入变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM