global $kernel fails in a legacy app being migrated to Symfony 5 [closed]

I’m upgrading a very old legacy application to use Symfony 5. I’ve created a LegacyBridge as suggested in the Symfony documentation and after some updates to the legacy code it works really well in both a docker development environment and on a “staging” server (CentOS 8) that I set up to help develop a proper deploy script.

The next step is to deploy to a production server, I’ve set that server up on Linode based on the staging server that I created before.

The problem I’m having on the production server is that everything seems to work just fine except for one thing, accessing the kernel with global seems to be impossible.
Symfony is loaded via index_symfony.php which is copied from the LegacyBridge documentation and the legacy code is in index.php

The legacy code uses global $kernel as suggested in the documentation to access the underlying PDO connection in Doctrine and use that instead of setting up its own database connection. However, all I get is this error:

Uncaught Error: Call to a member function getContainer() on null in /var/www.../public/index.php on line 14

Line 13 is global $kernel;:

require_once '../bootstrap.php';

// A few lines of comments

global $kernel;
$pdo = $kernel->getContainer()

I’ve tried various ways to work around this, looked into all possible scope issues that I can think of but all it does is move where the error is thrown.

The staging server is running PHP 7.4.4 (php-fpm with nginx) and the production server is running PHP 7.4.5 (php-fpm with nginx as well), both from remi:php-7.4 so there shouldn’t be any major differences.
My guess has been that there’s some configuration that I’m missing but I haven’t managed to find any differences that could possibly affect this.

Anyone have an idea what I can check?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *