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

Symfony2 post-update-cmd gives quot;An error occurred when generating the bootstrap filequot;(Symfony2 post-update-cmd 给出“生成引导文件时发生错误;)
本文介绍了Symfony2 post-update-cmd 给出“生成引导文件时发生错误";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Script SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap 处理 post-update-cmd 事件以异常终止[运行时异常]生成引导文件时出错.更新 [--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] ... [包N]

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

作曲家更新--no-scripts

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

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

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

Script SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap 处理 post-update-cmd 事件以异常终止[运行时异常]生成引导文件时出错.异常跟踪:() 在 C:xampphtdocsforvaltningvendorsensiodistribution-bundleSensioBundleDistributionBundleComposerScriptHandler.php:203SensioBundleDistributionBundleComposerScriptHandler::executeBuildBootstrap() 在 C:xampphtdocsforvaltningvendorsensiodistribution-bundleSensioBundleDistributionBundleComposerScriptHandler.php:43SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap() 在 phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:165ComposerEventDispatcherEventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:138ComposerEventDispatcherEventDispatcher->doDispatch() 在 phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:107ComposerEventDispatcherEventDispatcher->dispatchCommandEvent() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Installer.php:289ComposerInstaller->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Command/UpdateCommand.php:118ComposerCommandUpdateCommand->execute() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244SymfonyComponentConsoleCommandCommand->run() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:897SymfonyComponentConsoleApplication->doRunCommand() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191SymfonyComponentConsoleApplication->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:117ComposerConsoleApplication->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121SymfonyComponentConsoleApplication->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:83ComposerConsoleApplication->run() at phar://C:/ProgramData/Composer/bin/composer.phar/bin/composer:43C:ProgramDataComposerincomposer.phar:15 的 require()更新 [--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] ... [包N]

composer.json 包含:

<代码>{"name": "symfony/framework-standard-edition",许可证":麻省理工学院",类型":项目","description": ""Symfony 标准版" 发行版",自动加载":{psr-0":{":src/"}},存储库":[{类型":包",包裹": {"名称": "jquery/jquery",版本":1.9.1",距离":{"url": "http://code.jquery.com/jquery-1.9.1.js",类型":文件"}}}],要求": {"php": ">=5.3.3","symfony/symfony": "2.3.*",树枝/扩展":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.*"},需要开发":{phpunit/phpunit":3.7.*"},脚本":{安装后 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"],更新后-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"]},配置":{bin目录":bin"},最低稳定性":稳定",额外的": {symfony 应用程序目录":应用程序",symfony-web-dir":网络",incenteev 参数":{文件":app/config/parameters.yml"},分支别名":{开发大师":2.3-开发"}}

}

解决方案

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

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

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

最常见的解决方案:

在终端中执行以下命令:

rm -rf binrm -rf 供应商作曲家安装# 或者如果你没有安装 composerphp composer.phar 安装

现在应该可以工作了! 更多信息请参见 Symfony 安装.

如果仍然出现此错误生成引导文件时出错»
这意味着您有文件权限问题.
请参阅以下程序解决问题↓

设置或修复文件权限:

在终端中执行以下命令:

rm -rf app/cache/*rm -rf 应用程序/日志/*

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

HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v 根 | 头 -1 | 切 -d -f1)sudo chmod +a "$HTTPDUSER 允许删除、写入、追加、file_inherit、directory_inherit" 应用程序/缓存应用程序/日志sudo chmod +a "$(whoami) 允许删除、写入、追加、file_inherit、directory_inherit" 应用程序/缓存应用程序/日志

在大多数 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 根 | 头 -1 | 切 -d -f1)# 如果这不起作用,请尝试添加 `-n` 选项sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX app/cache app/logssudo 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);//这将使权限为 0775//或者umask(0000);//这将使权限为 0777

<块引用>

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

更多信息参见官方文档:Symfony 文件权限

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:

Script SensioBundleDistributionBundleComposerScriptHandler::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:

Script SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception

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

Exception trace:
 () at C:xampphtdocsforvaltningvendorsensiodistribution-bundleSensioBundleDistributionBundleComposerScriptHandler.php:203
 SensioBundleDistributionBundleComposerScriptHandler::executeBuildBootstrap() at C:xampphtdocsforvaltningvendorsensiodistribution-bundleSensioBundleDistributionBundleComposerScriptHandler.php:43
 SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:165
 ComposerEventDispatcherEventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:138
 ComposerEventDispatcherEventDispatcher->doDispatch() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:107
 ComposerEventDispatcherEventDispatcher->dispatchCommandEvent() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Installer.php:289
 ComposerInstaller->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Command/UpdateCommand.php:118
 ComposerCommandUpdateCommand->execute() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
 SymfonyComponentConsoleCommandCommand->run() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:897
 SymfonyComponentConsoleApplication->doRunCommand() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:191
 SymfonyComponentConsoleApplication->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:117
 ComposerConsoleApplication->doRun() at phar://C:/ProgramData/Composer/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:121
 SymfonyComponentConsoleApplication->run() at phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Console/Application.php:83
 ComposerConsoleApplication->run() at phar://C:/ProgramData/Composer/bin/composer.phar/bin/composer:43
 require() at C:ProgramDataComposerincomposer.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:

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

}

解决方案

How to solve install/update Symfony 2 issues

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

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:

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.

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 ↓

Setting up or Fixing File Permissions :

In a terminal execute following commands :

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

On macOS systems, the chmod command supports the +a flag to define an ACL. Use the following script to determine your web server user and grant the needed permissions:

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 BSD distributions don't support chmod +a, but do support another utility called setfacl. You may need to install setfacl and enable ACL support on your disk partition before using it. Then, use the following script to determine your web server user and grant the needed permissions:

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 umask so 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.php and web/app_dev.php files:

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.

For more information see official documentation : Symfony file permissions

这篇关于Symfony2 post-update-cmd 给出“生成引导文件时发生错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)