php Symfony2 post-update-cmd 给出“生成引导文件时发生错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20067622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:51:01  来源:igfitidea点击:

Symfony2 post-update-cmd gives "An error occurred when generating the bootstrap file"

phpsymfonycomposer-php

提问by Ronnie Jespersen

I am currently on Symfony2 2.3.7. When I run the composer update command. In the post-update-cmd a script is run to update symfony2. But it fails:

我目前在 Symfony2 2.3.7 上。当我运行 composer update 命令时。在 post-update-cmd 中运行一个脚本来更新 symfony2。但它失败了:

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception

  [RuntimeException]                                     
  An error occurred when generating the bootstrap file.  

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [packagesN]

Any idea why this is happening? I tried to run:

知道为什么会这样吗?我试着跑:

composer update --no-scripts 

.. and that runs fine. The following is also working fine:

.. 运行良好。以下也工作正常:

php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php

But everytime I try the normal composer update the post script fails. Running the update with --verbose gives the following:

但是每次我尝试正常的作曲家更新时,post 脚本都会失败。使用 --verbose 运行更新会得到以下结果:

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception

  [RuntimeException]                                     
  An error occurred when generating the bootstrap file.                                                      

Exception trace:
 () at C:\xampp\htdocs\forvaltning\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:203
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeBuildBootstrap() at C:\xampp\htdocs\forvaltning\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:43
 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:165
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:138
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:107
 Composer\EventDispatcher\EventDispatcher->dispatchCommandEvent() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Installer.php:289
 Composer\Installer->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Command/UpdateCommand.php:118
 Composer\Command\UpdateCommand->execute() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
 Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:897
 Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191
 Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:117
 Composer\Console\Application->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121
 Symfony\Component\Console\Application->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:83
 Composer\Console\Application->run() at phar://C:/ProgramData/Composer/bin/composer.phar/bin/composer:43
 require() at C:\ProgramData\Composer\bin\composer.phar:15

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [packagesN]

The composer.json contains:

composer.json 包含:

{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { "": "src/" }
},
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "jquery/jquery",
            "version": "1.9.1",
            "dist": {
                "url": "http://code.jquery.com/jquery-1.9.1.js",
                "type": "file"
            }
        }
    }
],
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.3.*",
    "twig/extensions": "1.0.*",
    "symfony/assetic-bundle": "2.3.*",
    "symfony/swiftmailer-bundle": "2.3.*",
    "symfony/monolog-bundle": "2.3.*",
    "sensio/distribution-bundle": "2.3.*",
    "sensio/framework-extra-bundle": "2.3.*",
    "sensio/generator-bundle": "2.3.*",
    "knplabs/knp-menu": "2.0.*@dev",
    "leafo/lessphp": "0.4.*@dev",
    "knplabs/knp-menu-bundle": "2.0.*@dev",
    "incenteev/composer-parameter-handler": "~2.0",
    "twbs/bootstrap": "2.3.*",
    "jquery/jquery": "1.9.*",
    "FortAwesome/Font-Awesome": "3.2.1",
    "egeloen/ckeditor-bundle": "2.*"
},
"require-dev": {
    "phpunit/phpunit": "3.7.*"
},
"scripts": {
    "post-install-cmd": [
        "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile"
    ],
    "post-update-cmd": [
        "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
        "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile"
    ]
},
"config": {
    "bin-dir": "bin"
},
"minimum-stability": "stable",
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    },
    "branch-alias": {
        "dev-master": "2.3-dev"
    }
}

}

}

回答by Antoine Subit

How to solve install/update Symfony 2 issues

如何解决安装/更新 Symfony 2 问题

One important Symfony requirement is that the app/cacheand app/logsdirectories must be writable both by the web server and the command line user.

Symfony 的一项重要要求是app/cacheapp/logs目录必须可由 Web 服务器和命令行用户写入。

On Linux and macOS systems, if your web server user is different from your command line user, you need to configure permissions properly to avoid issues. There are several ways to achieve that:

在 Linux 和 macOS 系统上,如果您的 Web 服务器用户与您的命令行用户不同,您需要正确配置权限以避免出现问题。有几种方法可以实现:

The most common solution :

最常见的解决方案:

In a terminal execute following commands :

在终端中执行以下命令:

rm -rf bin
rm -rf vendor
composer install
# or if your didn't install composer
php composer.phar install

It should work now!For more informations see Symfony installation.

它现在应该可以工作了!有关更多信息,请参阅Symfony 安装

If you still have this error: «An error occurred when generating the bootstrap file»
It means that you have file permission issue.
See below procedure for solve the problem ↓

如果您仍然出现此错误:« An error occurred when generating the bootstrap file»
这意味着您有文件权限问题。
看下面的步骤来解决问题↓

Setting up or Fixing File Permissions :

设置或修复文件权限:

In a terminal execute following commands :

在终端中执行以下命令:

rm -rf app/cache/*
rm -rf app/logs/*

On macOSsystems, the chmodcommand supports the +aflag to define an ACL. Use the following script to determine your web server user and grant the needed permissions:

在 macOS系统上,该chmod命令支持+a用于定义 ACL的标志。使用以下脚本确定您的 Web 服务器用户并授予所需权限:

HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "$(whoami) allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

On most Linux and BSDdistributions don't support chmod +a, but do support another utility called setfacl. You may need to install setfacland enable ACL supporton your disk partition before using it. Then, use the following script to determine your web server user and grant the needed permissions:

大多数 Linux 和 BSD发行版不支持chmod +a,但支持另一个名为setfacl. 在使用之前,您可能需要在磁盘分区上安装setfacl启用 ACL 支持。然后,使用以下脚本来确定您的 Web 服务器用户并授予所需的权限:

HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
# if this doesn't work, try adding `-n` option
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX app/cache app/logs
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX app/cache app/logs

If none of the previous methods work for you

如果之前的方法都不适合你

Change the umaskso that the cache and log directories are group-writable or world-writable (depending if the web server user and the command line user are in the same group or not). To achieve this, put the following line at the beginning of the app/console, web/app.phpand web/app_dev.phpfiles:

更改umask以便缓存和日志目录为组可写或全局可写(取决于 Web 服务器用户和命令行用户是否在同一组中)。为此,请将以下行放在app/console,web/app.phpweb/app_dev.php文件的开头:

umask(0002); // This will let the permissions be 0775
// or
umask(0000); // This will let the permissions be 0777

Note: Changing the umask is not thread-safe, so the ACL methods are recommended when they are available.

注意:更改 umask 不是线程安全的,因此建议在可用时使用 ACL 方法。

For more information see official documentation : Symfony file permissions

有关更多信息,请参阅官方文档:Symfony 文件权限

回答by Safwan Bakais

I think remove the folder bundles in the web directory "web/bundles" before running the update. This should solve the assets install problems in post-update-cmd

我认为在运行更新之前删除 web 目录“web/bundles”中的文件夹包。这应该可以解决 post-update-cmd 中的资产安装问题

回答by mattcrowe

I had the same problem and solved it in two parts. The crux of the problem was bad code on my part that wouldn't specifically apply to someone else, but my method for uncovering the issue might be useful to someone else.

我遇到了同样的问题,并分两部分解决了。问题的关键是我的代码不好,不能专门应用于其他人,但我发现问题的方法可能对其他人有用。

First, I created a temporary file: app/test.php

首先,我创建了一个临时文件:app/test.php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

/**
 * @var ClassLoader $loader
 */
$loader = require __DIR__.'/../vendor/autoload.php';

You'll notice that is a slimmed down version of app/autoload.php

您会注意到这是 app/autoload.php 的精简版

Next in my shell, I simply ran:

接下来在我的 shell 中,我简单地运行:

php app/test.php

After some trial and error, I discovered that I had an error in a private repo that I had as a requirement in my composer.json file. In my case, and I had a bootstrap file that was calling the very bootstrap.cache.php that we're trying to get composer to create.

经过一些试验和错误后,我发现我在我的 composer.json 文件中作为要求的私有存储库中存在错误。就我而言,我有一个引导程序文件,该文件正在调用我们试图让作曲家创建的 bootstrap.cache.php。

Anyway, this method was useful because it output errors that composer install/update would not, even with "--verbose" enabled and temporarily modifying the code to output all errors.

无论如何,这种方法很有用,因为它输出 composer install/update 不会的错误,即使启用了“--verbose”并临时修改代码以输出所有错误。

回答by ioses

Try to clean the cache with

尝试清理缓存

php app/console cache:clear

and then try again

然后再试一次

composer update

回答by BetaRide

I had the very same problem. Even calling

我有同样的问题。甚至打电话

composer create-project symfony/framework-standard-edition path/ "2.3.*"

in an empty directory failed.

在空目录中失败。

After all I rebooted and everything is fine again.

毕竟我重新启动,一切又好起来了。

回答by ADA15

this could also caused by an error in some controller, if your code is not clear then you can't update the composer . hope this help

这也可能是由某些控制器中的错误引起的,如果您的代码不清楚,那么您将无法更新 composer 。希望这有帮助

回答by user2048759

I came across the same problem running composer.phar installwith Symfony3 on Mac OS (Mavericks) with MAMP: script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception.

composer.phar install在 Mac OS (Mavericks) 上使用 MAMP运行Symfony3 时遇到了同样的问题:script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception.

Solved by updating the PHP version from 5.4 to 5.6. As Symfony runs inside MAMP, I forgot that my system default PHP version is not supported by Symfony3. After the PHP upgrade, the composer run with success.

通过将 PHP 版本从 5.4 更新到 5.6 来解决。由于 Symfony 在 MAMP 中运行,我忘记了 Symfony3 不支持我的系统默认 PHP 版本。PHP 升级后,composer 运行成功。

回答by Arleigh Hix

I ran into the same problem trying to use Symfony 3 on a Bluehost, shared hosting, server. I first had to find and use the php 5.4 client in order to get composer to run, then I got the same error you did. Check the docs here.

我在尝试在 Bluehost、共享主机、服务器上使用 Symfony 3 时遇到了同样的问题。我首先必须找到并使用 php 5.4 客户端才能运行 Composer,然后我遇到了与您相同的错误。 检查这里的文档。

PHP needs to be a minimum version of PHP 5.5.9

PHP 需要最低版本为 PHP 5.5.9

So you are using a php client that composer supports, and Symfony does not. Bluehost provides the php client v5.6.24 accessible at /usr/php/56/bin/php.

所以你使用的是 composer 支持的 php 客户端,而 Symfony 不支持。Bluehost 提供 php 客户端 v5.6.24,可在/usr/php/56/bin/php.

So, using that php executable:

因此,使用该 php 可执行文件:

/usr/php/56/bin/php ~/my/path/to/composer.phar install

I successfully ran "composer install" and all of the post-install-cmd's completed with no errors. This is also the way to call bin/consoleor in your case app/consolecommands. i.e.

我成功运行了“ composer install”,并且所有 post-install-cmd 都没有错误地完成。这也是调用bin/console或在您的情况下app/console命令的方式。IE

## Symfony 2
/usr/php/56/bin/php app/console cache:clear -e prod

## Symfony 3
/usr/php/56/bin/php bin/console cache:clear -e prod

回答by Roel B

I solved this by updating your composer.json to match the php version you have on your machine

我通过更新您的 composer.json 以匹配您机器上的 php 版本解决了这个问题

"config" : {
    "bin-dir" : "bin",
    "platform" : {
        "php" : "7.0.21" //Update this same as your $> php -v
    }
},

回答by Ryan Sundberg

In my case I had no permissions errors. It had to do with a require() for disabled PHP functions in the pnctl-event-loop-emitterlibrary. The composer autoloader was failing hard and crashed the script. The solution was to enable pcntl_ functions in php.ini.

就我而言,我没有权限错误。它与pnctl-event-loop-emitter库中禁用 PHP 函数的 require() 有关。作曲家自动加载器严重失败并导致脚本崩溃。解决方案是在 php.ini 中启用 pcntl_ 函数

The offending file was vendor/composer/../gos/pnctl-event-loop-emitter/src/functions.php

违规文件是 vendor/composer/../gos/pnctl-event-loop-emitter/src/functions.php

; This directive allows you to disable certain functions for security reasons.^M
; It receives a comma-delimited list of function names. This directive is^M
; *NOT* affected by whether Safe Mode is turned On or Off.^M
; http://php.net/disable-functions^M
; disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
disable_functions =