環境
- PHP 7.4.5
- Composer 1.10.5
事象
composer requireしようとしたら、メモリ確保できやんでと怒られた。
https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors を見ろと言われているので、それに従う。
$ composer require --dev nunomaduro/larastan
Using version ^0.6.1 for nunomaduro/larastan
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
手順
※下記の手順は、PHP全体のメモリ上限値を無制限に変更しています。
環境変数COMPOSER_MEMORY_LIMIT=-1
を設定し、Composerのメモリ上限値のみ変更することを推奨いたします。
(詳細はこちらを参照してください)
# memory_limitの設定値を確認
$ php -r "echo ini_get('memory_limit').PHP_EOL;"
128M
# php.iniの場所を確認
$ php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/etc/php/7.4
Loaded Configuration File => /usr/local/etc/php/7.4/php.ini
# memory_limitの設定値を更新
$ vi /usr/local/etc/php/7.4/php.ini
memory_limit = 128M
↓
memory_limit = -1
# memory_limitの設定値を確認
$ php -r "echo ini_get('memory_limit').PHP_EOL;"
-1
composer requireをやり直す
うまくいきました:D
$ composer require --dev nunomaduro/larastan
Using version ^0.6.1 for nunomaduro/larastan
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
略
Package manifest generated successfully.
44 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
memory_limitの設定値を元に戻す
# memory_limitの設定値を確認
$ php -r "echo ini_get('memory_limit').PHP_EOL;"
-1
# memory_limitの設定値を更新
$ vi /usr/local/etc/php/7.4/php.ini
memory_limit = -1
↓
memory_limit = 128M
# memory_limitの設定値を確認
$ php -r "echo ini_get('memory_limit').PHP_EOL;"
128M