为什么在ubuntu上安装Laravel 5.7我的fork失败-无法错误分配内存

时间:2019-06-14 15:37:49

标签: laravel-5 ubuntu-16.04

在LEMP / ASW下的ubunutu 16上安装Laravel 5.7应用程序时出现错误:

$ composer install
Cannot create cache directory /home/ubuntu/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/ubuntu/.composer/cache/files/, or directory is not writable. Proceeding without cache
Loading composer repositories with package information
Updating dependencies (including require-dev)

PHP Fatal error:  Uncaught ErrorException: proc_open(): fork failed - Cannot allocate memory in /usr/share/php/Symfony/Component/Console/Application.php:943
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', '/usr/share/php/...', 943, Array)
#1 /usr/share/php/Symfony/Component/Console/Application.php(943): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /usr/share/php/Symfony/Component/Console/Application.php(751): Symfony\Component\Console\Application->getSttyColumns()
#3 /usr/share/php/Symfony/Component/Console/Application.php(712): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /usr/share/php/Symfony/Component/Console/Application.php(645): Symfony\Component\Console\Application->getTerminalWidth()
#5 /usr/share/php/Symfony/Component/Console/Application.php(127): Symfony\Component\Console\Application->renderException(Object(RuntimeException), Object(Symfony\Component\Console\Output\StreamOutput))
#6 /usr/share/php/Composer/Console/Application. in /usr/share/php/Symfony/Component/Console/Application.php on line 943

Fatal error: Uncaught ErrorException: proc_open(): fork failed - Cannot allocate memory in /usr/share/php/Symfony/Component/Console/Application.php:943
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', '/usr/share/php/...', 943, Array)
#1 /usr/share/php/Symfony/Component/Console/Application.php(943): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /usr/share/php/Symfony/Component/Console/Application.php(751): Symfony\Component\Console\Application->getSttyColumns()
#3 /usr/share/php/Symfony/Component/Console/Application.php(712): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /usr/share/php/Symfony/Component/Console/Application.php(645): Symfony\Component\Console\Application->getTerminalWidth()
#5 /usr/share/php/Symfony/Component/Console/Application.php(127): Symfony\Component\Console\Application->renderException(Object(RuntimeException), Object(Symfony\Component\Console\Output\StreamOutput))
#6 /usr/share/php/Composer/Console/Application. in /usr/share/php/Symfony/Component/Console/Application.php on line 943

我想这是内存不足错误

phpinfo告诉我:

memory_limit    2056M   2056M
$ uname -a
Linux serge 4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


$ free
              total        used        free      shared  buff/cache   available
Mem:        1014384      224744      454504       13848      335136      611300
Swap:       1048572           0     1048572

$ whoami
ubuntu

我认为此内存必须足以容纳我的应用程序,但是为什么会出错? 我要注意哪些参数?

已修改: 我在/etc/php/7.2/fpm/php.ini和文件/etc/php/7.2/cli/php.ini文件中都检查了参数:

memory_limit = 2056M
max_execution_time = 3300 
max_input_time = 240 

upload_max_filesize = 200M 
post_max_size = 200M
output_buffering = on 
short_open_tag = On  

修改后的#2: 我仍然在寻找决定。我试图安装其他项目,该项目的已安装软件包数量较少(实际上是laravel / vuejs应用程序), 但是我遇到了同样的错误:

# composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing symfony/polyfill-ctype (v1.11.0)
    Downloading: 100%         
The following exception is caused by a lack of memory and not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Fatal error:  Uncaught ErrorException: proc_open(): fork failed - Cannot allocate memory in /usr/share/php/Symfony/Component/Console/Application.php:943
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', '/usr/share/php/...', 943, Array)
#1 /usr/share/php/Symfony/Component/Console/Application.php(943): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /usr/share/php/Symfony/Component/Console/Application.php(751): Symfony\Component\Console\Application->getSttyColumns()
#3 /usr/share/php/Symfony/Component/Console/Application.php(712): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /usr/share/php/Symfony/Component/Console/Application.php(645): Symfony\Component\Console\Application->getTerminalWidth()
#5 /usr/share/php/Symfony/Component/Console/Application.php(127): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#6 /usr/share/php/Composer/Console/Application.ph in /usr/share/php/Symfony/Component/Console/Application.php on line 943

Fatal error: Uncaught ErrorException: proc_open(): fork failed - Cannot allocate memory in /usr/share/php/Symfony/Component/Console/Application.php:943
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', '/usr/share/php/...', 943, Array)
#1 /usr/share/php/Symfony/Component/Console/Application.php(943): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /usr/share/php/Symfony/Component/Console/Application.php(751): Symfony\Component\Console\Application->getSttyColumns()
#3 /usr/share/php/Symfony/Component/Console/Application.php(712): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /usr/share/php/Symfony/Component/Console/Application.php(645): Symfony\Component\Console\Application->getTerminalWidth()
#5 /usr/share/php/Symfony/Component/Console/Application.php(127): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#6 /usr/share/php/Composer/Console/Application.ph in /usr/share/php/Symfony/Component/Console/Application.php on line 943
此项目的

composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "fzaninotto/faker": "^1.8",
        "intervention/image": "^2.4",
        "laracasts/utilities": "^3.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "orangehill/iseed": "^2.6",
        "pusher/pusher-php-server": "^3.4",
        "tymon/jwt-auth": "^1.0.0",
        "wboyz/laravel-enum": "^0.2.1",
        "zizaco/entrust": "^1.9"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "beyondcode/laravel-query-detector": "^1.0",
        "filp/whoops": "^2.0",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0",
        "xethron/migrations-generator": "^2.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

奇怪的是,我已经在Digital Ocean下的ubuntu 18中以相同的内存量安装了两个应用程序。 在AWS Ubuntu 16上

# lsb_release -d; uname -r; uname -i
Description:    Ubuntu 16.04.6 LTS
4.4.0-1084-aws
x86_64

# free
              total        used        free      shared  buff/cache   available
Mem:        1014384       48724      856564         700      109096      824368
Swap:       1048572      264404      784168

在Digital Ocean Ubuntu 18上(两个应用均可正常运行):

# lsb_release -d; uname -r; uname -i
Description:    Ubuntu 18.04.1 LTS
4.15.0-47-generic
x86_64
# free
              total        used        free      shared  buff/cache   available
Mem:        1009156      324640      109012       52520      575504      473160
Swap:       1048572      357888      690684

AWS Ubuntu 16上的错误原因是否可以正确配置某些东西? 尽管我同时安装和配置了这两个服务器,但是也许我错过了AWS Ubuntu 16上的某些功能?

谢谢!

1 个答案:

答案 0 :(得分:1)

这可能很晚,但可能会帮助某人。如果系统在Linux平台上,则只需导航到包含.composer目录的目录,然后将权限设置为允许(递归)所有用户组的(读取,写入,执行)权限。这对我有用

chmod 777 -R /home/$USER/.composer 

然后您可以在项目目录中运行

composer update