Memory limit- how to increase increase memory limit PHP-FPM/FastCGI

Hi,

I’m testing M2.4.3-p1 installation but this time on Nginx + php-fpm.
The installation process was painless but I struggle to increase the memory limit.

I followed the Magento official documentation setting php

In short, I modified /etc/php/7.4/cli/php.ini & /etc/php/7.4/fpm/php.ini.
Pls. see my setting below.

date.timezone = Europe/London
**memory_limit = 4096M**
max_execution_time = 1800
zlib.output_compression = On
realpath_cache_size=10M
realpath_cache_ttl=7200

opcache.save_comments=1
opcache.enable=1

I also modified the Magento default nginx.conf file increasing the default 756M to 4096M.
I referred to this post.

# PHP entry point for setup application
location ~* ^/setup($|/) {
    root $MAGE_ROOT;
    location ~ ^/setup/index.php {
        fastcgi_pass   fastcgi_backend;

        fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=4098 \n max_execution_time=600";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

By doing the above I was able to increase the memory limit for the master value only the local value remains at 756M

Can you please give me a tip on how to increase the local value too?
Thank you.

Reg,
Pawel

Hi Pawel,
have you tried setting the value in your .htaccess file. I think that changes the local value if i remember correctly…

normallly if you put this in your .htaccess file then it should change the local value:

php_value memory_limit 4G

In 2.4, the .htaccess file that states the memory_limit has been moved from Magento Root Directory to the Pub Directory. This file overrides values set in your global PHP Configuration files.

Example
/var/www/html/pub/.htaccess

Hi Craig & Andy,

Thank you for your prompt response.
Editing values in the .htaccess file won’t help. I think that Nginx webserver doesn’t support it.

Nginx doesn’t support .htaccess (see here: “You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.” ).

I think it is something to do with Nginx & php.fpm. I found this article " Nginx or PHP FPM ignores memory_limit in php.ini" and experimenting.

I added the folowing line the the to /etc/php/7.4/fpm/pool.d/www.conf file
php_value[memory_limit] = 2048M
This didn’t work so I replaced the line with
php_admin_value[memory_limit] = 2048M
The only difference between both, according to the article, is that the second cannot be overridden by *.ini files or ini_set().

Now, I can see that the memory_limit Local value has been increased to 4096M. Why 4096, not 2048??? :thinking:

After the memory_limit Loval Value has been increased I haven’t got access to my Magento.

It can’t be difficult I just need to find a good source of info.

I need to config this correctly for M2E Pro.

" 3. If PHP is running using the FastCGI module on your web server it may override execution time settings in php.ini or .htaccess files. If there are additional FastCGI settings, you need to review all the directives in your FastCGI configuration which can possibly affect the time settings in Magento. Paying attention to the following ones:

- request_terminate_timeout
- FcgidBusyTimeout
- FcgidIdleTimeout
- FcgidIOTimeout etc."

Can you guys give me a tip on how to bite it?
Thank you in advance.

Reg,
Pawel

I’m still fighting with correctly increasing the Local value memory limit.

From what I read in the default www.conf file (/etc/php/7.4/fmp/pool.d)
There are no default values defined except the value in php.ini. Values in php.ini are set correctly.

Please add anything you can find.

@digitalstartup Craig, it would be great if you record a tutorial on how to set up Mag on Nginx + Php-fpm. :slight_smile: The installation process is pretty easy. It might be useful for the ‘DS’ community.

I only struggle with the memory settings. :rage:

If my job ever entails using Nginx + PHP-FPM I might. But my experience is purely with Apache.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.