52

Recently I started a project in Symfony2 from the BETA version available on symfony.com

After a while, I needed to upgrade to the master branch, so I retrieved the latest from github and switched it in vendor/symfony.

However, my bootstrap.php.cache and bootstrap_cache.php.cache are not upgraded, which has generated errors.

I tried clearing the symfony cache, to no avail.

How can I update these files to correspond to my project?

j0k
  • 22,600
  • 28
  • 79
  • 90
jihi
  • 1,346
  • 2
  • 13
  • 22
  • 1
    see my answer here: http://stackoverflow.com/questions/29919275/strange-doctrine-entitynotfoundexception/31664345#31664345 – shacharsol Jul 27 '15 at 23:12

9 Answers9

67

In the 2.0 release the original file is here:

./vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php

Edit: in release 2.3 the file is here

vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
mogoman
  • 2,286
  • 24
  • 28
  • This doesn't appear to do anything in my project when I run the above script (this is also after I updated my vendors' bundles). Any ideas on troubleshooting this? – Eno Nov 14 '11 at 18:35
  • @Eno did you try removing (make a backup first) the bootstap cache files and then running the script? – mogoman Nov 15 '11 at 10:42
  • 14
    `composer update` is all you need now (Symfony 2.3 + Composer) – J. Bruni Jul 30 '13 at 01:10
  • 3
    `composer update` also updates the dependencies that is not what **jihi** asked for! please check my answer. it shows how it should be done: http://stackoverflow.com/a/26337973/828366 – Francesco Casula Oct 13 '14 at 10:38
  • 2
    For 2.3 (and 3.0) it's now `php vendor/sensio/distribution-bundle/Resources/bin/build_bootstrap.php` – flu Jun 14 '16 at 10:32
66

If you run the composer update command you will also update your project dependencies which is not the desired behaviour here. If you do that you'll have to test the new changes to see if they do affect your application somehow.

So if you just want to rebuild your bootstrap cache file then I suggest you run the post-update-cmd command.

Therefore you should use:

composer run-script post-update-cmd

which in my case executes the following scripts (see composer.json):

"scripts": {
    "post-install-cmd": [
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrapSass"
    ]
}

Please consider that you can also create a new set of scripts in there to just rebuild the bootstrap file and clears the cache without installing the assets and so on:

"scripts": {
    "reset-bootstrap-cmd": [
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache"
    ]
}

and then... composer run-script reset-bootstrap-cmd

Francesco Casula
  • 26,184
  • 15
  • 132
  • 131
28

In the latest 2.1.0-DEV, the actual script is here:

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

Gregoire
  • 3,735
  • 3
  • 25
  • 37
22

I'm using Symfony Standard 2.0.9 (without Vendors).

To update bootstrap.php.cache, just run

php bin/vendors update

This will update all vendors (including Symfony itself) and always call that build_bootstrap.php script for you.

seb
  • 2,350
  • 24
  • 30
  • 3
    Indeed, `composer update` triggers the "build bootstrap" script. This is the current up-to-date answer. – J. Bruni Jul 30 '13 at 01:08
17

Have you tried running:

php bin/build_bootstrap.php

This will regenerate the bootstrap files

d.syph.3r
  • 2,215
  • 1
  • 19
  • 14
11

You might prefer to use composer install which "re-installs" the system to the state definied in the composer.lock file and generates autoloads and bootstrap.php.cache. Using composer update updates all packages and changes the state of your system.

dfri
  • 126
  • 1
  • 4
3

I feel like the build_bootstrap script is always changing location :)

So, if you are working with several Symfony versions and don't know where the build_bootstrap is, this will do the trick (Linux/Mac only):

$ cd vendor/ 
$ find . -name build_bootstrap.php
NDM
  • 6,731
  • 3
  • 39
  • 52
Victor Henriquez
  • 1,399
  • 15
  • 26
  • Never remember the exact name, so every time I have to type this command. `find . -iname "*build*bootstrap*php"` – MGP Sep 16 '13 at 18:59
1

i couldnt fix a problem on my bootstrap cache, nor update it . i was getting alot of this

[Symfony\Component\Debug\Exception\ContextErrorException] Warning: Invalid argument supplied for foreach() in /home/sites/fuji/app/bootstrap.php.cache line 2870

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

although they were great suggestions, and i did try the rebuilding of bootstrap cache file after backing it up, and to run composer update these still gave me the same problem.

Solution for me: i shelled into the pc with the site files on it, rm -rf app/cache/* -R removed everything inside the cache directory then i was able to run both composer update, AND clear cache etc.. with no problems.

blamb
  • 4,220
  • 4
  • 32
  • 50
1

Search for where the "build_bootstrap.php" located at.

for my case in Symfony3.4

php ./vendor/sensio/distribution-bundle/Resources/bin/build_bootstrap.php
Yuseferi
  • 7,931
  • 11
  • 67
  • 103