Contact us
Servers 1 min read · 07/2021

NGINX, PHP-FPM and memory_limit

Setting the PHP memory limit in the NGINX and PHP-FPM configuration

In PHP-FPM, memory_limit is set to 128MB by default. If you need to change this limit, you can set the desired value using the fast_cgi_param directive:

nginx
fastcgi_param PHP_VALUE "memory_limit = 1G";

For a Symfony application, the configuration can look like this, for example:

nginx
location ~ ^/index\.php(/|$) {
    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_param PHP_VALUE "memory_limit = 1G";

    # Prevents URIs that include the front controller. This will 404:
    # http://domain.tld/index.php/some-path
    # Remove the internal directive to allow URIs like this
    internal;
}
Share
LinkedIn Facebook

Need more than an article?

Get in touch with no obligation – a few sentences about what you are dealing with are enough.

Read on

Similar articles

More notes from operations and development.

All advice