LoginSignup
3
4

More than 3 years have passed since last update.

composerを用いたインストール中にメモリ系のエラーが出た話

Last updated at Posted at 2020-06-14

目的

  • composerインストール中に出たメモリ系のエラーの解決方法をまとめる。

実施環境

  • ハードウェア環境
項目 情報
OS macOS Catalina(10.15.5)
ハードウェア MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
プロセッサ 2 GHz クアッドコアIntel Core i5
メモリ 32 GB 3733 MHz LPDDR4
グラフィックス Intel Iris Plus Graphics 1536 MB
  • ソフトウェア環境
項目 情報 備考
AWS EC2インスタンス AmazonLinux2 こちらの方法を用いてイメージからインスタンスを作成→AWS EC2 をMacで使ってみよう!
PHP 7.4.5 こちらの方法でインストール→AWS EC2 AmazonLinux2 PHPをインストールする
composer 1.10.7 こちらの方法でインストール→AWS EC2 AmazonLinux2 composerをインストールする

読後感

  • 下記に記載するメモリ系エラーが発生せずにcomposerインストールが正常に完了する。

問題までの経緯

  1. 下記の方法でEC2のインスタンスを作成した。
  2. 下記の方法でPHP7.4.Xをインストールした。
  3. 下記の方法でcomposerをインストールした。
  4. 下記コマンドを実行してLaravelをインストールしようとした。

    $ composer global require laravel/installer
    

問題

  • 下記の様なエラーが発生しcomposerインストールが行えない。

    The following exception is caused by a lack of memory or swap, or not having swap configured
    
  • エラーの全文を下記に記載する。

    $ composer global require laravel/installer
    Changed current directory to /home/ec2-user/.config/composer
    Using version ^3.1 for laravel/installer
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 20 installs, 0 updates, 0 removals
      - Installing symfony/polyfill-php80 (v1.17.0): Downloading (100%)
        proc_open(): fork failed - Cannot allocate memory
        The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
        Unzip with unzip command failed, falling back to ZipArchive class
    
    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
    
    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
    
    require [--dev] [--prefer-source] [--prefer-dist] [--fixed] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...
    

問題解決までの経緯

  1. エラー文に記載されているリンクを閲覧してみる。

  2. 何やらエラーに関する解決方法の記載があった。

    このページを翻訳しますか?_と_Troubleshooting_-_Composer.png

  3. 公式ドキュメントに従いコマンドを実行してみる。

  4. 下記コマンドを実行して現在のスワップ領域の確認を行う。

    $ free -m
    
  5. 下記の様に出力された。スワップ領域の割り当てが0になってしまっていることが原因の様だ。

    $ free -m
                  total        used        free      shared  buff/cache   available
    Mem:            983         378         465           0         139         465
    Swap:             0           0           0
    
  6. 下記コマンドを実行してスワップ領域を設定する。(/bin/dd: failed to open ‘/var/swap.1’: Text file busyと出力されてしまった方はAWSのEC2コンソールより一旦インスタンスを再起動する。Linuxの物理マシンで実施中の方もLinux物理マシンを再起動する。※インスタンス再起動後はssh接続のコマンドが変化するため注意する。)

    $ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
    $ sudo /sbin/mkswap /var/swap.1
    $ sudo /sbin/swapon /var/swap.1
    
  7. 再度Laravelインストールコマンドを実行すると正常に実行できた。

参考文献

3
4
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
3
4