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.
I tried the solution #gilden gave in his comment; it works.
I ran php bin/console cache:clear --env=prod instead of rm -rf app/cache/*.
I'm surprised that nobody told you:
you have no route for / on the prod environment.
write this in app/config/routing.yml
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
You need to install APC for your local server, and everything will work in prod mod for you.
Also try to hit correct database in parameters.yml, because dev is adding DATABASENAME_dev.
Today I had the same problem and tried various solutions. Until I remembered that it is important to have the mod_rewrite apache service enabled. To do this run the following command (on Ubuntu)
sudo a2enmod rewrite
And then restart the server
sudo service apache2 restart
I hope that someone can be helpful.
Regards!
My symfony cache folder was not writable. It worked when i made the cache complete directory and its files as writable.
sudo chmod -R 777 .
(Agrega esto dentro del archivo routing_dev.yml) Add this in routing_dev.yml
_wellcome:
pattern: /
defaults: { _controller:AppBundle:Default:index }
Related
I have a Symfony instance running on Linux with apache y NGINX. I'am starting the project using the built-in server:start command:
php bin/console server:start
Back to my browser, it loads me the Symfony start page but it also shows me the debug bar.
I have checked the config_dev.yml file and I think it is correct:
imports:
- { resource: config.yml }
framework:
router:
resource: '%kernel.project_dir%/app/config/routing_dev.yml'
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
However, if I try to access another route that I don't have, the debug bar is also shown:
You can access the prod env with:
http://127.0.0.1:8000/app.php
And accessing http://127.0.0.1:8000/app.php/a will give you an error page without the debug bar.
It is designed like this because the Symfony built-in web server is only meant to be used in development not in production. So the default environment is the "dev" one.
I'm developping a Symfony 2 application (version 2.6.1) but I can only run it on PROD mode. When trying to access to the following URL :
http://localhost/lawAdmin/web/app_dev.php
I'm having the next error message:
RouteNotFoundException in appDevUrlGenerator.php line 32: Unable to
generate a URL for the named route "_profiler" as such route does not
exist.
Both my routing.yml and routing_dev.yml files look the same:
law_admin:
resource: "#LawAdminBundle/Controller/DefaultController.php"
type: annotation
prefix: /
Running
app/console debug:router
returns:
[router] Current routes
Name Method Scheme Host Path
porfolio_show GET ANY ANY /
gallery_show GET ANY ANY /gallery/{galleryId}
I've also tried the following command just in case unsuccessfully:
php app/console cache:clear
Change your routing dev to
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_main:
resource: routing.yml
This will load profiler and toolbar routes on dev environment, and load your own application routes from routing.yml file.
I am trying to route a subdomain to a specific bundle in Symfony2. Here's what I've got:
I added local domains to my hosts:
127.0.0.1 todolist.lc
127.0.0.1 manager.todolist.lc
I created a virtual host that forwards all subdomains to my Symfony installation:
<VirtualHost 127.0.0.1>
ServerName todolist.lc
ServerAlias *.todolist.lc
DirectoryIndex app_dev.php
DocumentRoot "C:\xampp\htdocs\todolist\web"
</VirtualHost>
I created a new Bundle to handle the subdomain manager.todolist.lc:
Now I am trying to set up the route to manager.todolist.lc:
frontend:
resource: "#FrontendBundle/Controller/"
type: annotation
prefix: /
backend:
resource: "#BackendBundle/Controller/"
type: annotation
prefix: /api
manager:
host: manager.todolist.lc
resource: "#ManagerBundle/Controller/"
type: annotation
prefix: /
Now after I added the manager route I get a FileLoaderImportCircularReferenceException on every route there is.
I also tried to use a prefix, but this also gives the Exception:
manager:
resource: "#ManagerBundle/Controller/"
type: annotation
prefix: /manager
I can't figure out what I am missing. What am I doing wrong? If you need any more info, just ask for it in the comments and I'll provide it.
Ok. Here's what I was missing:
1. I forgot to load the bundle into the AppKernel
Obviously, this is very important:
new FrontendBundle\FrontendBundle(),
new BackendBundle\BackendBundle(),
new ManagerBundle\ManagerBundle(),
2. The subdomain needs to be declared before the main domain
After I loaded the bundle into the AppKernel the application would still route to the FrontController. I solved this by changing the order of my routes:
manager:
host: manager.todolist.lc
resource: "#ManagerBundle/Controller/"
type: annotation
prefix: /
frontend:
resource: "#FrontendBundle/Controller/"
type: annotation
prefix: /
backend:
resource: "#BackendBundle/Controller/"
type: annotation
prefix: /api
After changing the order of the routes both manager.todolist.lc and todolist.lc worked.
I'm using FOS User bundle to allow users to register and log in to my app. Until now it works just fine but i don't know how to get my hand on those views? Can i generate them somehow? Documentation doesnt seem to know anything about it, just about overriding templates, which is not what i need...
At first i thought routing file might be of some use, since it points to specific places in the project, but it lists folders I dont even have in my application
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
There is no FOSUserBundle directory at all...
You can find third party bundles installed in the vendor directory.
In this case, #FOSUserBundle should be a pointer to vendor/friendsofsymfony/user-bundle/FOS/UserBundle/.
If you don't have that directory, try running this on your project root: composer update.
Overriding templates is well documented here
I have just installed Symfony2 and created my bundle. I removed the Acme demo bundle and tested my new route "/" which worked fine.
I then went to config.php and followed the link to _configurator and get the above route error. I also get the same error when trying to load _profiler.
Here is my route file:
asf_core_homepage:
pattern: /
defaults: { _controller: ASFCoreBundle:Home:index }
And the Symfony routing_dev file:
_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
Any ideas why this is happening?
EDIT
I have narrowed it down and it looks like it has nothing to do with symfony. I have it installed in a subfolder of root so I use htaccess to rewrite all requests from /forum to /forum/web
RewriteRule forum/(.*) /forum/web/$1 [L]
If I point the browser to /forum/app_dev.php it works fine. the error comes from /forum/app_dev.php/_configurator
But if I skip the rewrite rule and use /forum/web/app_dev.php/_configurator it works fine.