简体   繁体   中英

Heroku rejects push because it cannot clear the cache Symfony3

Working all day to deploy my application to heroku, but every time it throws out an error. And i am all out of clues, and have a very angry customer.

When i try to add my project to heroku with the command git push heroku master every thing is fine till the cache needs to be cleared.

Updating the "app/config/parameters.yml" file
remote:        > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
remote:        > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
remote:        Could not open input file: app/console
remote:        Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
remote:
remote:
remote:          [RuntimeException]
remote:          An error occurred when executing the "'cache:clear --no-warmup'" command:
remote:          Could not open input file: app/console
remote:          .

You would think, it's the same as this git issue

Also a know problem, that i am using a wrong type of mapping.

在此处输入图片说明

But i think it's fine.

I updated my composer and cleared the cache of my composer

And when i clear the cache with p hp bin/console cache:clear everything is fine!

I followed this tutorial And got some side information from the symfony site.

Also found this stack - with the explanation what is going on, but this is still not solving my problem.

Maybe it's somewhere in my composer file, or my git ignore. But honestely, i have no idea anymore.

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-4": { "": "src/" },
        "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
    },
    "autoload-dev": {
        "psr-4": { "Tests\\": "tests/" }
    },
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.1.*",
        "doctrine/orm": "^2.5",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^2.8",
        "symfony/polyfill-apcu": "^1.0",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "^2.0",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "symfony/assetic-bundle": "^2.8",
        "stfalcon/tinymce-bundle": "2.0",
        "egeloen/ckeditor-bundle": "^4.0",
        "whiteoctober/tcpdf-bundle": "^1.0",
        "gregwar/captcha-bundle": "^2.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "symfony-scripts": [
            "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",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ],
        "compile": [
            "rm web/app_dev.php",
            "bin/console cache:clear",
            "bin/console assetic:dump"
        ]
    },
    "config": {
        "platform": {
            "php": "5.5.9"
        }
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "3.1-dev"
        }
    }
}

You upgraded a Symfony 2 app to 3.

But it is not sufficient to change the requirements in composer.json .

The structure changed, so you need to first create a new fresh app with Symfony 3 and then move the old Symfony 2 app to the fresh Symfony 3 one, bundle by bundle, composer requirement by composer requirement.

This way you'll be sure your app will work well on version 3.

If you try to simply upgrade the requirements from a Symfony 2 app, then you'll create a lot of bugs, as the scripts changed, the structure changed, the requirements changed...

The only safe way is to start a new Symfony 3 project and then port the old Symfony 2 into it.

The solution that worked for me. New Symfony 3 installation: Could not open input file: app/console in composer install

EXPLANATION:

That's what I guess. When you push your code to Heroku, the platform compiles your project files on the /tmp dir. What happens if you don't have a var dir when Heroku compiles your code? What happens is that Symfony creates a new one:

vendor/sensio/distribution-bundle/Composer/ScriptHandler.php:462

protected static function useNewDirectoryStructure(array $options)
{
    return isset($options['symfony-var-dir']) && is_dir($options['symfony-var-dir']);
}

Then when Heroku moves your new code to the /app dir, the Symfony configuration still points to the old placement /tmp , but files placed at /tmp are now deleted!

I took a look at your github repository. Seems like it's in the Symfony3 format, so I'm not certain what is going on. I want to try something, but I'm not sure if it will work.

Try editing your composer.json file manually to add the bin directory:

"config": {
        "bin-dir": "bin",
        "platform": {
            "php": "5.5.9"
        }
},

Then see if that fixes the problem.


EDIT #2

Now revert those changes and try this:

"extra": {
    "symfony-app-dir": "bin",
    "symfony-bin-dir": "bin",
    "symfony-var-dir": "var",

In other words change the app directory to "bin".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM