26

Server info: Ubuntu Server, Nginx, PHP FPM

in /etc/php5/fpm/php.ini I have: memory_limit = 512M in /etc/php5/fpm/php-fpm.conf I have: php_admin_value[memory_limit] = 512M

php_value[memory_limit] = 512M

My phpinfo looks like:

PHP Version 5.3.10-1ubuntu3.6

System Build Date

Linux snserver 3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:10 UTC 2013 x86_64 Mar 11 2013 14:34:24

Server API

FPM/FastCGI

Virtual Directory Support

disabled

Configuration File (php.ini) Path

/etc/php5/fpm 

Loaded Configuration File

/etc/php5/fpm/php.ini

Scan this dir for additional .ini files /etc/php5/fpm/conf.d

Additional .ini files parsed

/etc/php5/fpm/conf.d/curl.ini, /etc/php5/fpm/conf.d/gd.ini, /etc/php5/fpm/conf.d/mcrypt.ini, /etc/php5/fpm/conf.d/memcache.ini, /etc/php5/fpm/conf.d/mysql.ini, /etc/php5/fpm/conf.d/mysqli.ini, /etc/php5/fpm/conf.d/pdo.ini, /etc/php5/fpm/conf.d/pdo_mysql.ini ...

This server is protected with the Suhosin Patch 0.9.10 Copyright (c) 2006-2007 Hardened-PHP Project Copyright (c) 2007-2009 SektionEins GmbH

This program makes use of the Zend Scripting Language Engine: Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans

...

memory_limit

128M

upload_max_filesize

20M

in /etc/nginx/nginx.conf:

    user www-data;

worker_processes 2;

pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    client_max_body_size 20M;

    ##

    # Basic Settings

    ##
    fastcgi_buffers 16 16k;

    fastcgi_buffer_size 32k;

    proxy_buffers 4 512k;

    proxy_buffer_size 256k;

    proxy_busy_buffers_size 512k;

    fastcgi_read_timeout 3600;

    sendfile on;

    tcp_nopush on;

    tcp_nodelay on;

    keepalive_timeout 300;

    keepalive_requests 50;

    #ssl_ciphers HIGH:!aNULL:!MD5:!kEDH;

        #ssl_prefer_server_ciphers on;

        #ssl_protocols TLSv1;

        #ssl_session_cache shared:SSL:10m;

        #ssl_session_timeout 10m;

    types_hash_max_size 2048;

    # server_tokens off;

    # server_names_hash_bucket_size 64;

    # server_name_in_redirect off;

    include /etc/nginx/mime.types;

    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;

    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

The problem is when i change upload_max_filesize size then the phpinfo will show the new value, but when I change memory_limit then nothing changes. I guess in somewhere the memory_limit is overwrited. But i cannot find it. Can anyone help me?

8 Answers 8

35

In /etc/php5/fpm/php-fpm.conf I have php_admin_value[memory_limit] = 512M

This works for me.

5
  • For me as well, changing it in php.ini wasn't enough, even though it was picked up according to phpinfo() (using php 5.4.26)
    – Willem
    Jun 17, 2015 at 20:00
  • 3
    Don't forget to restart php-fpm and nginx after you make these edits. Feb 17, 2017 at 18:33
  • 1
    in /etc/php5/fpm/pool.d/www.conf removed php_admin_value[memory_limit] = 32M after php5-fpm restart in then changes for memory_limit in the /etc/php5/fpm/php.ini file
    – asherrard
    Mar 14, 2017 at 19:36
  • 1
    As per pilot's answer elsewhere, good idea to fully stop/start php-fpm rather than restart, so you can be sure all the old processes have cleared. Sep 27, 2017 at 8:56
  • After several days of researching the problem, you found the key to the problem. Thanks!! Jan 20, 2021 at 10:31
17

The problem may be in fpm the process duplication, even you change your /etc/php5/fpm/php.ini it was not effect.

  • Stop php5-fpm with (ubuntu): sudo service php5-fpm stop
  • check that no more fpm processes: sudo ps ax | grep fpm
  • if any kill it all with: sudo kill -9 pid
  • be sure that you kill all fpm processes
  • restart: sudo service php5-fpm restart
2
  • This worked for me, there were 3 duplicate fpm processes running because of which it was not taking the changed value until you kill all the fpm processes and restart php5-fpm
    – Chakri
    May 26, 2017 at 18:49
  • Best to perform this as a script for minimum downtime in production.
    – roshnet
    Dec 7, 2022 at 5:56
11

You can take Nginx out of the picture, it just passes the request on, it's in php-fpm running your php code.

you might check your suhosin settings, suhosin.memory_limit.

when you see your phpinfo output there should be 2 columns, master and local for memory_limit, what do these each show?

128M is the default for memory_limit in php 5.3

0
8

For me it also ignored php.ini and I had to do the following:

vim /etc/php-fpm.d/www.conf

php_admin_value[memory_limit] = 10000M ;128M

Then restart php-fpm:

service php-fpm restart
1
  • thanks, this was my problem and it help solve my problem.
    – user618886
    Jul 14, 2021 at 3:51
6

Just FYI,

you should also check in /etc/php5/fpm/pool.d for any files.

It just happened to me that no matter what I wrote on /etc/php5/fpm/php-fpm.conf it would get overrided by /etc/php5/fpm/pool.d/www.conf !

So if none of the above answers are not working for you, you should check this (I just lost half hour to this).

3

Also encountered this now and wanted to increase memory of our server in a DigitalOcean droplet

To summarize, here is what I did

sudo nano /etc/php5/fpm/php-fpm.conf

-- press Ctrl-W to do a search in nano text editor
-- if php_admin_value[memory_limit] is there, change it
php_admin_value[memory_limit] = 512M

sudo service php5-fpm restart

You don't need to restart nginx, just restarting php would be enough.

0

Ok this is daft but I had memory_limit set to 2GB, which isn't understood. When I changed that to 2000M it worked!

1
  • Maybe need to set 2G, instead of 2GB Sep 29, 2022 at 9:17
0

The file I needed to edit was /etc/php/8.1/cli/php.ini - found that out by running phpinfo() in the script itself rather than viewing it through the browser - nginx.

phpinfo() in the browser indicated Loaded Configuration File /etc/php/8.1/fpm/php.ini

phpinfo() in the console indicated Loaded Configuration File /etc/php/8.1/cli/php.ini

Not sure why, Im not investigating further rn, just glad that I found it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.