Nicolas GAUTHIER
Nicolas GAUTHIER

Reputation: 121

Symfony error: Class 'Symfony\Component\HttpKernel\Kernel' not found

After upgrading from Symfony 3.1 to 3.2 I get this error message :

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in /var/www/html/HeliosBlog/app/AppKernel.php on line 6

Here's what my app/autoload.php looks like:

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;

if (!$loader = @include __DIR__.'/../vendor/autoload.php') {

    $message = <<< EOF

EOF;

    if (PHP_SAPI === 'cli') {
        $message = strip_tags($message);
    }

    die($message);
}

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

Here's what my app_dev.php file looks like:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], array(
            '127.0.0.1',
            'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

And here's what my AppKernel.php looks like:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{

    public function registerBundles()
    {
        $bundles = array(
            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 JMS\AopBundle\JMSAopBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Helios\BlogBundle\HeliosBlogBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Helios\UserBundle\HeliosUserBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new FOS\ElasticaBundle\FOSElasticaBundle(),
            new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
            new Helios\ManagerBundle\HeliosManagerBundle(),
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            //new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
            new Oneup\UploaderBundle\OneupUploaderBundle(),
            new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
        );

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

            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
            $bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Already tried removing the vendor folder and doing a composer install.

Any ideas?

Upvotes: 10

Views: 21437

Answers (4)

leberknecht
leberknecht

Reputation: 1714

I was able to solve it by simply adding

require_once __DIR__.'/autoload.php';

to app/console before

require_once __DIR__ . '/AppKernel.php';` 

Upvotes: 14

Arthur
Arthur

Reputation: 3797

I had this issue while running composer update, because it was still using app/console (probably outdated) instead of the new bin/console.

I fixed this issue by:

  • removing app/console file.
  • creating a var/ folder in my project root directory - see this answer for explanation.

Upvotes: 3

dinel
dinel

Reputation: 56

I run into this problem as well while updating my project from Symfony 2.x (can't remember whether it was 2.7 or 2.8) to 3.2. In turn out that the problem was caused by the app/console file. I believe the problem is caused by the way I created the project ages ago.

To solve this problem, I copied the app/console file from another project which I successfully upgraded to 3.2. I am not sure whether there will be some other problems down the line, but at least I got rid of this error.

The discussion that prompted me to make this change is https://github.com/symfony/symfony/issues/16713

Upvotes: 2

Rico Humme
Rico Humme

Reputation: 476

Ran into the same error. Found that the bootstrap.php.cache was unaware of the Kernel class. This happened due the Sensio Distibution bundle having an update. For this I posted an issue which can be found here: https://github.com/sensiolabs/SensioDistributionBundle/issues/302

I hope this helps others as well.

Upvotes: 4

Related Questions