Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in {project directory}\symfony\app\AppKernel.php on line 7 #124

Open
daifma opened this issue Oct 15, 2016 · 3 comments

Comments

@daifma
Copy link

daifma commented Oct 15, 2016

Hello;
I'm interested in using symfony and Wordpress but at the first install a get this error
Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in {project directory}\symfony\app\AppKernel.php on line 7
My PHP version is 5.6
My symfony version is 2.8
My wordpress version is 4.6.1

@terox
Copy link

terox commented Dec 16, 2016

I am experiencing the same issue using the same versions (with a little tweaked worpdpress docker container)

@terox
Copy link

terox commented Dec 16, 2016

@daifabde I think that example of wordpress index.php is outdated or use something new in Symfony 3.x. Try the new index.php file. It worked for me:

<?php

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

/**
 * Retrieves or sets the Symfony Dependency Injection container
 *
 * @param ContainerInterface|string $id
 *
 * @return mixed
 */
function symfony($id)
{
    static $container;

    if ($id instanceof ContainerInterface) {
        $container = $id;
        return;
    }

    return $container->get($id);
}

$loader = require __DIR__.'/../symfony/app/autoload.php';
require_once __DIR__.'/../symfony/app/bootstrap.php.cache';

// Load application kernel
require_once __DIR__.'/../symfony/app/AppKernel.php';

$sfKernel = new AppKernel('dev', true);
$sfKernel->loadClassCache();
$sfKernel->boot();

// Add Symfony container as a global variable to be used in Wordpress
$sfContainer = $sfKernel->getContainer();

if (true === $sfContainer->getParameter('kernel.debug', false)) {
    Debug::enable();
}

symfony($sfContainer);

$sfRequest = Request::createFromGlobals();
$sfResponse = $sfKernel->handle($sfRequest);
$sfResponse->send();

$sfKernel->terminate($sfRequest, $sfResponse);

As you will see the path to bootstrap.php.cache was changed into app/ (older/newer versions of Symfony works with var/ but I haven't known what versions exactly). The error is related with autoload.php (inexistent) in the original file by the same reasons (the Symfony versions).

I hope that it solves your headaches

@wiejakp
Copy link

wiejakp commented Nov 5, 2017

As of 11/01/2017 and Symfony 3.3 :)

<?php

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

/**
 * Retrieves or sets the Symfony Dependency Injection container
 *
 * @param ContainerInterface|string $id
 *
 * @return mixed
 */
function symfony($id)
{
    static $container;

    if ($id instanceof ContainerInterface) {
        $container = $id;
        return;
    }

    return $container->get($id);
}

$loader = require __DIR__.'/../symfony/vendor/autoload.php';
require_once __DIR__.'/../symfony/var/bootstrap.php.cache';

// Load application kernel
require_once __DIR__.'/../symfony/app/AppKernel.php';

$sfKernel = new AppKernel('dev', true);
$sfKernel->loadClassCache();
$sfKernel->boot();

// Add Symfony container as a global variable to be used in Wordpress
$sfContainer = $sfKernel->getContainer();

if (true === $sfContainer->getParameter('kernel.debug', false)) {
    Debug::enable();
}

symfony($sfContainer);

$sfRequest = Request::createFromGlobals();
$sfResponse = $sfKernel->handle($sfRequest);
$sfResponse->send();

$sfKernel->terminate($sfRequest, $sfResponse);

autoload.php will be located at: symfony/vendor/autoload.php
And bootstrap.php.cache at: symfony/var/bootstrap.php.cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants