10

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?

3
  • looking at the error Kernel and AppKernel, fishy. care to post what does AppKernel contains? Commented Dec 27, 2016 at 1:16
  • Use the standard Symfony autoload.php and get rid of the rest of the nonsense. And while we on the subject, use the standard app_dev.php file as well. Commented Dec 27, 2016 at 3:05
  • I used the standard autpload.php and app_dev.php files, and deleted the cache folder manually, but nothing has changed. Commented Dec 27, 2016 at 14:08

4 Answers 4

14

I was able to solve it by simply adding

require_once __DIR__.'/autoload.php';

to app/console before

require_once __DIR__ . '/AppKernel.php';` 
Sign up to request clarification or add additional context in comments.

2 Comments

This is a deperecated answer for Symfony 3, isn't it ?
Hm, possible, yes. I ran into this when updating from 2.8 to 3.1 (with keeping the console script in app/console-directory). But i would not say that it is "deprecated", as the base-take-away "ensure that you have autoload included before including the kernel" is still valid (even though that should indeed already be the case if you install symfony from scratch).
4

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.

2 Comments

That seems unlikely. The bootstrap cache file preloads certain classes for performance reasons. All other classes will still be autoloaded as needed. I suspect he has version issues resulting in an empty vendor directory.
Downgraded the Sensio Distribution bundle from 5.0.15 to 5.0.14, and the error is indeed gone. Hope this will be fixed soon.
3

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.

Comments

2

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

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.