2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHPのmemory_limitのデフォルト値を変更する

Posted at

次のようなメモリ制限のエラーが出た時の対処法。デフォルトでは128Mになっているので、-1(上限なし)に変更する。

PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes)

現在のメモリ上限を確認する。

$ php -r "echo ini_get('memory_limit').PHP_EOL;"

128M

php.iniファイルの場所を確認する。

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File:         /usr/local/etc/php/7.3/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.3/conf.d/ext-opcache.ini

/usr/local/etc/php/7.3/php.ini ファイルの memory_limit の値を書き換える。

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = -1             ; この行を128から-1に書き換える

メモリ上限を確認して、変更が反映されていたらOK。

$ php -r "echo ini_get('memory_limit').PHP_EOL;"

-1

参考資料:
https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?