I have recently successfully installed Symfony2 on my machine.
I can access http:/localhost/app_dev.php
(dev environment)
However, when I try to access the prod environment:
http:/localhost/app.php
I get the following error message in the browser:
Oops! An Error Occurred
The server returned a "404 Not Found". Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
I have checked the obvious: The file app.php does exist in the same folder as app_dev.php - so I don't know whats causing this.
Does anyone have a solution to fix this?
[[Edit]]
I have cleared the cache by typing: sudo php app/console cache:clear env=prod no-debug
as recommended. I now get a blank screen. Worryingly, there are no error messages logged in app/logs/prod.log, so I have not got the faintest idea as to what is wrong (prod environment still works just fine).
Contents of my app/config/routing.yml file:
### fos routing, remove later
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
###
# Internal routing configuration to handle ESI
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal
Here is my app/config/routing_dev.yml file
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
_demo_secured:
resource: "@AcmeDemoBundle/Controller/SecuredController.php"
type: annotation
_demo:
resource: "@AcmeDemoBundle/Controller/DemoController.php"
type: annotation
prefix: /demo
_assetic:
resource: .
type: assetic
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
I just noticed that I DO NOT have a routing_prod.yml**
(alarm bells ringing) - does Symfony2 not ship with a production routing config file?
My Apache configuration file content is shown below:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /path/to/symfony/web
ServerName localhost
# Custom log file
Loglevel warn
ErrorLog /path/localhost.error.log
CustomLog /path/localhost.access.log combined
<Directory /path/to/symfony/web>
AllowOverride None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
</VirtualHost>
[[Further Details]]
Contents of app/logs/prod.log
[2012-08-10 18:10:38] security.INFO: Populated SecurityContext with an anonymous Token [] [] [2012-08-10 18:10:38] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /" (uncaught exception) at /path/to/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php line 83 [] []
Have you turned on the production environment and cleared the cache? Run the console and do this:
app/console --env=prod cache:clear
I think I had a similar problem. I believe warming up the cache solved my instance if it.
php app/console cache:warmup --env=prod --no-debug
Having recently installed Symfony 2.2 I ran into this issue too but it's actually the normal behavior. Meaning out of the box Symfony 2.x (as of this writing) doesn't ship with any routes/content for the production environment.
In your case it looks you installed the Friends of Symfony bundle, which did setup some routes in your production route (routing.yml
), but at a glance none of the routes seem to be targeting the root of your production environment i.e. http:/localhost/app.php/
so the 404 is probably expected. I can't be totally sure though since it's importing routes so the details are obscured. A great way to check your routes is to read up on Visualizing & Debugging Routes where you can learn about the app/console router:debug
CLI command.
routing.yml
is the default place for routes in your production environment (meaning routing_prod.yml
isn't a thing). You'll notice routing_dev.yml
imports routing.yml
. That means that everything that you put in production is (out of the box) accesible in the development. The demo content you see is exclusive to the dev environment so that's why you're not seeing it in the production. Feel free to move some stuff around to suite your needs but it's generally a good idea for the dev to import the production but not vice versa.
Any time you want to test out the changes in your production you'll want to clear your cache as @tolgap recommends. The production environment leans heavily on the precompiled cache, so that command will force your production cache to refresh. The dev environment is always refreshing it's cache. Understanding this is crucial to working with Symfony. Though the Book on Symfony.org is a great entry point it doesn't exactly drive home this point about the subtitles of caching and workflow. I was definitely confused for a minute before I realized the relationship between routing.yml
and routing_dev.yml
and the soft caching of the dev versus the hard caching of the production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With