Skip to content
iD-SIGN
Contact us

NGINX, PHP-FPM and memory_limit

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

1 min readpublished 7/2021

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 fastcgi_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;
}

Tags Servers, PHP, Nginx

Share LinkedIn Facebook

Need more than an article?

A few sentences about what you are dealing with are enough.