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

时间:2013-11-19 09:24:11

标签: php symfony composer-php

我目前正在使用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]

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

composer update --no-scripts 

..而且运行正常。以下工作正常:

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

但每次我尝试普通的作曲家更新时,帖子脚本都会失败。 使用--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]

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"
    }
}

}

11 个答案:

答案 0 :(得分:25)

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

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

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

最常见的解决方案:

在终端中执行以下命令:

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

现在应该可以使用了!有关更多信息,请参阅Symfony installation

如果您仍有此错误:«An error occurred when generating the bootstrap file»
这意味着您有文件权限问题。
请参阅以下解决问题的步骤↓

设置或修复文件权限:

在终端中执行以下命令:

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

在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

在大多数Linux和BSD 发行版中,不支持chmod +a,但支持另一个名为setfacl的实用程序。在使用之前,您可能需要在磁盘分区上安装setfaclenable ACL support。然后,使用以下脚本确定您的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

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

更改umask,以便缓存和日志目录可以写入组或可写入世界(具体取决于Web服务器用户和命令行用户是否在同一组中)。要实现此目的,请将以下行放在app/consoleweb/app.phpweb/app_dev.php文件的开头:

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

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

有关详细信息,请参阅官方文档:Symfony file permissions

答案 1 :(得分:0)

我认为在运行更新之前,请删除web目录“web / bundles”中的文件夹包。这应解决post-update-cmd

中的资产安装问题

答案 2 :(得分:0)

我遇到了同样的问题并分两部分解决了。问题的症结在于我的代码不是特别适用于其他人的代码,但我发现问题的方法可能对其他人有用。

首先,我创建了一个临时文件: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';

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

接下来在我的shell中,我只是跑了:

php app/test.php

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

无论如何,这种方法很有用,因为它输出的错误是作曲家安装/更新所不会的,即使用" - verbose"启用并临时修改代码以输出所有错误。

答案 3 :(得分:0)

尝试使用

清理缓存
php app/console cache:clear

然后再试一次

composer update

答案 4 :(得分:0)

我遇到了同样的问题。甚至打电话

composer create-project symfony/framework-standard-edition path/ "2.3.*"
空目录中的

失败。

毕竟我重新启动,一切都很好。

答案 5 :(得分:0)

这也可能是由某些控制器中的错误引起的,如果您的代码不清楚则无法更新作曲家。希望这个帮助

答案 6 :(得分:0)

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

通过将PHP版本从5.4更新到5.6来解决。当Symfony在MAMP内部运行时,我忘记了Symfony3不支持我的系统默认PHP版本。 PHP升级后,作曲家运行成功。

答案 7 :(得分:0)

我遇到了同样的问题,试图在Bluehost,共享主机,服务器上使用Symfony 3。 我首先必须找到并使用php 5.4客户端才能让作曲家运行,然后我遇到了同样的错误。 Check the docs here.

  

PHP需要是PHP 5.5.9的最低版本

所以你使用的是作曲家支持的php客户端,而Symfony却没有。 Bluehost提供了/usr/php/56/bin/php ~/my/path/to/composer.phar install 访问的php客户端v5.6.24。

所以,使用那个php可执行文件:

composer install

我成功运行了“bin/console”并且所有post-install-cmd都已完成,没有任何错误。 这也是调用app/console或您的案例## 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 命令的方法。 即。

a = map(lambda x: float(x),a)
b = map(lambda x: float(x),b)
np.dot(a,b.T)

答案 8 :(得分:0)

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

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

答案 9 :(得分:0)

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

有问题的文件是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 =

答案 10 :(得分:-1)

我也看到了这个错误。在我的情况下,当我在php.ini中禁用APC扩展时,错误停止了。