Symfony production environment throws 500 error: D

2019-07-18 02:39发布

问题:

I'm learning Symfony2, really cool stuff. But I do run into some trouble when I want to try and visit the production environment. I have followed the Symblog Tutorial that is located here: http://tutorial.symblog.co.uk/

I have cleared the cache and I visit http://symfony.dev/ I have running locally. The page remains totally blank and this error is in the log:

Fatal error: Uncaught exception 'Doctrine\ORM\ORMException' with message 'Unknown Entity namespace alias 'DSBlogBundle'.' 
in /Applications/MAMP/htdocs/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:236 
Stack trace: 
#0 /Applications/MAMP/htdocs/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Configuration.php(194): Doctrine\ORM\ORMException::unknownEntityNamespace('DSBlogBundle') 
#1 /Applications/MAMP/htdocs/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(554): Doctrine\ORM\Configuration->getEntityNamespace('DSBlogBundle') 
#2 /Applications/MAMP/htdocs/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(194): Doctrine\ORM\Mapping\ClassMetadataFactory->getFqcnFromAlias('DSBlogBundle', 'Blog') 
#3 /Applications/MAMP/htdocs/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(295): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('DSBlogBundle:Bl...') 
#4 /Applications/MAMP/htdocs/symfony/vendor in /Applications/MAMP/htdocs/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php on line 236

What I don't get is that the 'Unknown Entity namespace alias 'DSBlogBundle' is perfectly "known" in the development environment. Does anyone know what I am missing? Any help is much appreciated! Thank you!

回答1:

Couple possibilities I can think of:

1) If your code functions properly in the development environment, then it could be a cache problem and/or a permissions problem. Make sure your files are readable by the user/process associated with your web server and make sure the prod cache directory is writable by that user so it can generate the necessary files. What I generally do is run the clear cache console command AS that user to avoid unexpected cache problems, like this (on linux):

sudo -u www-user php app/console cache:clear --env=prod

If you're developing on linux, you must be logged in as either root or another user with administrator privileges to run a command as a user other than yourself.

2) You may have configurations defined in the dev environment that don't exist in the prod environment. Double check the files in your app/config folder. My first guess would have been that the DSBlogBundle wasn't correctly defined in app/AppKernel.php but I believe that's environment independent so it couldn't work in dev but not prod.