部署到Heroku

时间:2019-01-12 13:13:16

标签: php symfony heroku doctrine-orm heroku-cli

我正在尝试将Symfony应用程序部署到Heroku,但是当我运行命令git push heroku master时出现错误:

  

未捕获的错误:在/tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19

中找不到类'Doctrine \ Bundle \ FixturesBundle \ DoctrineFixturesBundle'

错误日志:

Generating optimized autoload files 
remote: > Incenteev\ParameterHandler\ScriptHandler::buildParameters 
remote: Creating the "app/config/parameters.yml" file 
remote: > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap 
remote: > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 
remote: PHP Fatal error: Uncaught Error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19 
remote: Stack trace: 
remote: #0 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles() 
remote: #1 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles() 
remote: #2 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot() 
remote: #3 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() 
remote: #4 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\Framewor in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php on line 19 
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: 
remote: 
remote: 
remote: PHP Fatal error: Uncaught Error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php:19 
remote: Stack trace: 
remote: #0 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles() 
remote: #1 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles() 
remote: #2 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot() 
remote: #3 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() 
remote: #4 /tmp/build_808fab60090f288d282076c72569d1ad/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\Framewor in /tmp/build_808fab60090f288d282076c72569d1ad/app/AppKernel.php on line 19 
remote: 
remote: 
remote: install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]... 
remote: 
remote: ! WARNING: There was a class not found error in your code 
remote: 
remote: ! ERROR: Dependency installation failed! 

我的AppKernel::registerBundles()

    public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
            new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle(),
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
            }
        }

        return $bundles;
    }

composer.json(“需要”块)

{
    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-migrations-bundle": "^1.3",
        "doctrine/orm": "^2.5",
        "incenteev/composer-parameter-handler": "^2.0",
        "knplabs/doctrine-behaviors": "^1.4",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.3.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    }
}

我需要做什么?

1 个答案:

答案 0 :(得分:2)

您已经安装了“ doctrine / doctrine-fixtures-bundle”用于开发:

"require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },

但是正在尝试在生产中使用它。

在部署应用程序时,heroku使用--no-dev标志安装作曲家依赖项,该标志会跳过require-dev中声明的软件包。

当应用程序尝试运行AppKernel::registerBundles()时,它将尝试实例化Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle,但未安装该软件包。

您应该删除第19行(new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),)并将其添加到以下代码段的某个位置:

if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
           // ^^^^^ this line here

这是在检查环境是dev还是test,并且仅在这些环境下尝试使用这些软件包。