PHP Composer update “cannot allocate memory” error (using Laravel 4)

后端 未结 26 1370
天命终不由人
天命终不由人 2020-11-29 14:46

I just can\'t solve this one.

I\'m on Linode 1G RAM basic plan. Trying to install a package via Composer and it\'s not letting me. My memory limit is set to \"-1\" o

相关标签:
26条回答
  • 2020-11-29 15:34

    This seems to be a recurring issue with 1GB and smaller server instances. Apart from trying to shutdown processes and tweak swap settings, you could install on a local machine and upload.

    0 讨论(0)
  • 2020-11-29 15:34

    In my case I tried everything that was listed above. I was using Laravel and Vagrant with 4GB of memory and a swap, with memory limit set to -1. I deleted the vendor/ and tried other PHP-versions. Finally, I managed it to work by running

    vagrant halt
    vagrant up
    

    And then composer install worked again as usual.

    0 讨论(0)
  • 2020-11-29 15:35

    As composer troubleshooting guide here This could be happening because the VPS runs out of memory and has no Swap space enabled.

    free -m
    

    To enable the swap you can use for example:

    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
    

    Or if above not worked then you can try create a swap file

    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    
    0 讨论(0)
  • 2020-11-29 15:36

    Sometimes by self-updating composer it solves the problem

    php composer.phar self-update
    

    Cheers

    0 讨论(0)
  • 2020-11-29 15:37

    Try that:

    /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
    
    /sbin/mkswap /var/swap.1
    
    /sbin/swapon /var/swap.1
    
    0 讨论(0)
  • 2020-11-29 15:38

    I use it for 500MB RAM and it works for me.

    php -d memory_limit=-1 /usr/local/bin/composer install
    
    0 讨论(0)
提交回复
热议问题