Migrating Legacy PHP application to Symfony 5, strange issue with globals
I have a strange issue with, I'm guessing, php-fpm configuration.
I'm migrating a legacy application in to Symfony 5. So far it's gone pretty well with a LegacyBridge and everything works fine locally in a docker container and on a newly installed "staging" server, a KVM virtual machine running CentOS 8.
Now that everything is working fine in development the next step is to go live. I've set up a Standard Linode with CentOS 8 configured as close to my staging server as I've been able to copy. MariaDB, nginx and php-fpm 7.4.5 from remi:php-7.4.
Symfony is loaded via
index_symfony.php which loads the legacy code via
index.php I have the following code:
13 global $kernel; 14 $pdo = $kernel->getContainer() ->get('doctrine.orm.default_entity_manager') ->getConnection() ->getWrappedConnection();
On my local setup and on the staging server this works just fine but on the Linode I get this:
PHP Fatal error: Uncaught Error: Call to a member function getContainer() on null in /var/www/.../public/index.php on line 14
If I on the other hand copy that same code to
index_symfony.php (after kernel instantiation, adding
global $pdo) those lines work just fine but both the
$kernel objects seem to disappear before
index.php is loaded.
I've tried messing around with the PHP code to work around this issue but now I'm pretty sure that there's some configuration or possibly extension that I'm missing.
Anyone have an idea?
Unless $kernel and $pdo are declared inside a function/method, they probably shouldn't be declared global…they are de-facto global.
If you add
to your composer.json and do a composer update and then add
$whoops = new \Whoops\Run; $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); $whoops->register();
to your index.php at the very top right after
you will get a nice tombstone with a backtrace about your failure. Note that $whoops in the above snippet would be global.