9

I need to increase the memory limit for PHP on the command line so I can use Composer.

Output of php -i | grep memory_limit

memory_limit => 256M => 256M

Output of php --ini

Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File:         /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed:      /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-igbinary.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-memcache.ini,
/usr/local/php5/php.d/50-extension-memcached.ini,
/usr/local/php5/php.d/50-extension-mongo.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-oauth.ini,
/usr/local/php5/php.d/50-extension-pdo_dblib.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-redis.ini,
/usr/local/php5/php.d/50-extension-solr.ini,
/usr/local/php5/php.d/50-extension-ssh2.ini,
/usr/local/php5/php.d/50-extension-twig.ini,
/usr/local/php5/php.d/50-extension-uploadprogress.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xhprof.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini

So I edit /usr/local/php5/lib/php.ini but it's always 256MB...

Restarted Apache, but it's cli, but still no success.

miken32
  • 42,008
  • 16
  • 111
  • 154
Codium
  • 3,200
  • 6
  • 34
  • 60
  • Make sure you edit the correct `php.ini` – Xorifelse Mar 17 '17 at 17:05
  • Check [this answer](http://stackoverflow.com/questions/9343151/where-is-php-ini-in-mac-os-x-lion-thought-it-was-in-usr-local-php5-lib). It's for Lion, but I think it still applies for Sierra – gmc Mar 17 '17 at 17:27
  • Thanks, but in my case it seems to be outdated – Codium Mar 18 '17 at 17:17

3 Answers3

14

One of the other included files has a memory_limit directive. Use this command to find which one:

grep memory_limit /usr/local/php5/php.d/*

The "Additional .ini files parsed" are parsed later, and will override settings in the main php.ini.

miken32
  • 42,008
  • 16
  • 111
  • 154
10

Maybe you should find out where php.ini is

sometimes this won't do:

php -i | grep php.ini   # turns out I just can't edit /etc/php.ini even when I'm root

then you can try this:

locate php.ini  # turns out it's here: /private/etc/php.ini

finally, edit /private/etc/php.ini with sudo

sudo vim /private/etc/php.ini 

save the file with

:wq!

job done.

Randy Lam
  • 579
  • 5
  • 11
  • saving with :wq!, translates to quit without saving => ! discards the changes – Gunnrryy Dec 24 '20 at 09:12
  • @Gunnrryy :wq! just means force write and quit in one command. If the file was modified and you wanted to quit without saving, you would use :q!. – Randy Lam Mar 10 '21 at 05:20
  • In what cases will `php -i` not give you accurate information about which ini files are being applied? I’m not sure macOS comes with `vim`, but if you feel the need to give instructions on how to quit `vi` then why not how to enter insert/append mode? The directive could be in any of multiple files not named `php.ini`, as in the OP’s case, where they already edited that file to no effect. – miken32 Mar 31 '21 at 13:13
2

I found out that you need to change the memory limit in this file :

/usr/local/etc/php/*your php version*/conf.d/php-memory-limits.ini

Worked like a charm after modifying this file.