Set memory_limit to PHP FPM with .htaccess

1.2k Views Asked by At

I need to modify in the htaccess the memory_limit, max_input_vars and max_execution_time of php. In order not to modify the global configuration of php on the server.

In my virtualhost, I have this configuration:

<FilesMatch \.php> 
    SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/" 
</FilesMatch> 

In my htaccess I have tested these two configs without success:

<IfModule php7_module>
    php_value memory_limit 512M
    php_value max_input_vars 10000
    php_value max_execution_time 1800
</IfModule>

And

<IfModule mod_php7.c>
    php_value memory_limit 512M
    php_value max_input_vars 10000
    php_value max_execution_time 1800
</IfModule>

In the case of php7.3-fpm.sock, do I have to use it another way?

Thanks

2

There are 2 best solutions below

2
Kleber Holtz On

in your configuration file, default path "/etc/php/7.3/fpm/pool.d/php7.3-fpm.conf" or your path, change to:

php_admin_value[memory_limit] = 512M
php_admin_value[max_input_vars] = 10000
php_admin_value[max_execution_time] = 1800

then restart your web service, and test your settings.

0
DGzeule On

php-fpm and mod-php are two different ways to use php with an apache webserver. The .htaccess rules only work with mod-php. The IfModule rule ensures that they are only executed if mod-php is in use. In both cases you can use the php function set_time_limit(1800) and ini_set('memory_limit', '512M') in your PHP-code to change the time- and memory-limits (if allowed by the server config).