7

Composer fails to install symfony in the production environment. Everything works fine in development. All permissions are fine.

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioGeneratorBundle" from namespace "Sensio\Bundle\GeneratorBundle".
Did you forget a "use" statement for another namespace? in /home/ev/app/AppKernel.php:25
Stack trace:
#0 /home/ev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(396): AppKernel->registerBundles()
#1 /home/ev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(114): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /home/ev/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(68): Symfony\Component\HttpKernel\Kernel->boot()
#3 /home/ev/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(118): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/ev/bin/console(27): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Inp in /home/ev/app/AppKernel.php on line 25

This is line 25 of AppKernel.php:

$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

Any suggestions are welcome :)

1

4 Answers 4

8

In Prod environnment, the SensioGeneratorBundle is not registred. This bundle should be defined like a dev bundle as follow :

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

And inside your composer file :

"require-dev": {
    "sensio/generator-bundle": "~2.3"
}

If you want to use generation commands from this bundle in Prod env, you should move the declaration from dev to Prod (not recommended!)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! This fixed my issue
i think it's as stated by @jeremy by default right ?
1

This also depend of your goal:

  • if you want to setup a prod env : run composer install --no-dev and SYMFONY_ENV=prod and the error should go away.

Comments

1

in my case Sensio Generator Bundle is deprecated in Symfony 4, so you may comment or delete this 2 lines below.

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

Comments

0

This worked for me:

$ cd project_folder
$ composer dump-autoload

This reloads files and loads your settings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.