Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

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

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

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...