Symfony2 update-cmd 给出“生成引导文件时出错”如何解决安装/更新Symfony 2问题

2022-08-30 17:14:10

我目前在Symfony2 2.3.7上。当我运行作曲家更新命令时。在更新后 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"
    }
}

}


答案 1

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

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

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

最常见的解决方案:

在终端中执行以下命令:

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

它现在应该工作了!有关详细信息,请参阅 Symfony 安装

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

设置或修复文件权限 :

在终端中执行以下命令:

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

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

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 发行版上不支持 ,但支持另一个名为 .在使用磁盘分区之前,您可能需要在磁盘分区上安装并启用 ACL 支持。然后,使用以下脚本确定 Web 服务器用户并授予所需的权限:chmod +asetfaclsetfacl

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

如果上述方法都不适合您

更改掩码,使缓存和日志目录是组可写的或全域可写的(取决于 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

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

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


答案 2

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


推荐