composer报错 proc_open(): fork failed - Cannot allocate memory

在Linux服务器使用composer创建laravel项目 composer create-project laravel/laravel laravel --prefer-dist "5.3.*" 报错.


[root@iZ23bm1tc0pZ wwwroot]# composer create-project laravel/laravel laravel --prefer-dist "5.3.*"
Installing laravel/laravel (v5.3.30)
  - Installing laravel/laravel (v5.3.30): Loading from cache
Created project in laravel
> php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 61 installs, 0 updates, 0 removals
  - Installing vlucas/phpdotenv (v2.4.0): Loading from cache
    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
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 979
Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 979
  [ErrorException]
  proc_open(): fork failed - Cannot allocate memory


提示内存不足,我们可以通过创建swap分区解决这个问题。


在命令行环境依次运行以下三条命令

dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
mkswap /var/swap.1
swapon /var/swap.1
[root@iZ23bm1tc0pZ wwwroot]# dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
记录了1024+0 的读入
记录了1024+0 的写出
1073741824字节(1.1 GB)已复制,32.1777 秒,33.4 MB/秒
[root@iZ23bm1tc0pZ wwwroot]# mkswap /var/swap.1
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=c32ccbf6-6e72-4f32-917e-5b6f5e02b154
[root@iZ23bm1tc0pZ wwwroot]# swapon /var/swap.1


解释:

dd 从/dev/zero设备复制出一个1G大小的文件/var/swap.1

mkswap 格式化/var/swap.1

swapon 将swap分区挂在到文件系统

然后输入free -m 查看内存使用量信息


[root@iZ23bm1tc0pZ wwwroot]# free -m
             total       used       free     shared    buffers     cached
Mem:           488        482          6         14          2        344
-/+ buffers/cache:        136        352
Swap:         1023          0       1023

再次运行 composer create-project laravel/laravel laravel --prefer-dist "5.3.*" 即可创建成功

composer报错 proc_open(): fork failed - Cannot allocate memory》上有 1 条评论!

  1. 爵士
    博主很厉害

发表评论