How do I increase PHP memory limit on Ubuntu 14.04

May 17, 2015 16.5k views


I am using a 1GB Droplet with current kernel: Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)

Using phpinfo() I have identified the currently loaded php.ini file, and have updated the memory_limit attribute to 512M from 128.

This file is /etc/php5/fpm/php.ini

Despite making this change (and of course restarting nginx and php5-fpm services - as well as rebooting the entire server after each change), the value shown in phpinfo() remains at 128M

Other things I've tried (again, have rebooted/restarted services):

  • Adding the following values to /etc/php5/fpm/php-fpm.conf
php_admin_value[memory_limit] = 512M
php_value[memory_limit] = 512M
  • Adding a user.ini file in /etc/php5/fpm/conf.d/ (as this directory is scanned for other config files) - and adding the memory_limit with 512M memory

  • Editing /etc/php5/cli/php.ini to the same 512M value, even though this file isn't being used.

  • Adding a php.ini file with the updated memory_limit value inside the root of the web site's directory

I am absolutely stumped, and if someone can offer any insights or further troubleshooting steps, I would be greatly appreciative!


3 Answers

Hi smarterdigitalltd,

What version of php are you using exactly?

I'm not sure what the problem is, but I thought the following might help:

  • If you're making modification to many php.ini, just stick to the one phpinfo() shows.
  • If there is a syntax error within php.ini, it might not parse the rest of th file.
  • It seems possible to change the memory limit from .htaccess
  • Maybe increase post_max_size?
  • Compare php -i with phpinfo()
  • Look for other instances of memory_limit inside php.ini
  • Is it possible to check some sort of php logs to look for potential errors?
  • The suhosin extension is known to limit memory settings. Check if you use it.
  • Try initset e.g. ```iniset("memory_limit","256M");```
  • Try lowering it first, to see if there's any changes.

Hope this helps.

Hi Enigma

Wow - great tips; thanks for sending such a detailed list.

So, to answer your questions in order:

  • Yep, I put the other ini files back to default.
  • Item I downloaded another php.ini from a working droplet that uses the same image - no luck.
  • No luck with .htaccess
  • No luck with postmaxsize
  • I'm not sure if you mean changing the post_max_size will have an impact on memorylimit, but when I change the `postmax_size` value in the same PHP.ini file, it is reflected in phpinfo()
  • Interestingly, no - php -i returns /etc/php/cli/php.ini - however I tried editing this file previously with no luck.
  • No other instances of memory_limit
  • I've checked the logs, and they look clear - other than a recurring notice:

[17-May-2015 16:44:57] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

  • I couldn't find much information as to where I should look for this extension so I tried to uninstall it, and I was told that it didn't exist.
  • No luck
  • Yes I tried lowering to 64M - no change
  • My PHP version is 5.5.9-1ubuntu4.9

So other than point 6 - where the php.ini files don't reconcile, it all seems to check out OK. Perhaps I have to check out the suhosin stuff more, but as I said - I didn't have much luck finding out how to configure this. Any other thoughts or pointers are of course welcomed!


  • Ok, maybe a few more things to try:

    • Try setting memory_limit = -1
    • Just to confirm, have you tried: ini_set('memory_limit', '128M');
    • So the memory limit seems fixed, e.g. you tried both increasing and lowering it to no avail, right?
    • It's obvious, put you're actually writing it like this: memory_limit = 128M (with the M at the end)
    • Can you try echoing the memory_limit? : php -r "echo ini_get("memory_limit").PHP_EOL"
    • Maybe try telling apache to use a specific php.ini file. (Look under Finding the path of the php.ini file)
    • I don't think safe_mode still exists for this version of php, but perhaps it's set somewhere (I'm being a bit desperate now)

    Let me know how it goes.

Maybe it's too late but just for reference as I wasted three hours trying to increase the memory limit for Magento.

Turns out that this was set in the .htaccess file for the virtual host.

Have another answer? Share your knowledge.