Raspberry Piでcomposerを実行すると Cannot allocate memoryと表示される

2020年3月21日土曜日

Laravel Raspberry Pi

t f B! P L
Raspberry Pi上のLaravelプロジェクトにcomposerでlaravel-corsを入れようとすると、次のようなエラーが出ました。

$ composer require fruitcake/laravel-cors
Using version ^1.0 for fruitcake/laravel-cors
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing fruitcake/laravel-cors (v1.0.5):
Installation failed, reverting ./composer.json to its original content.
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Warning:  proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952

Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952

  [ErrorException]
  proc_open(): fork failed - Cannot allocate memory

解決方法

使ってなさそうなサービスなどをstopしてメモリを解放すれば解決すると思ったのですが、だめでした。swapを増やしてみると解決しました。

スワップの増やし方


$sudo vi /etc/dphys-swapfile
// CONF_SWAPSIZEを変更する
CONF_SWAPSIZE=1024

$sudo systemctl restart dphys-swapfile

再度、composerを実行すると正常にlaravel-corsがプロジェクトに追加されました。

$ composer require fruitcake/laravel-cors
Using version ^1.0 for fruitcake/laravel-cors
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing fruitcake/laravel-cors (v1.0.5): Loading from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: barryvdh/laravel-cors
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.

このブログを検索

ブログアーカイブ

QooQ