symfony2.3 routing doesn't work on prod env - php

I'm trying to create a /contact route on my website using symfony on windows environment.
I added in the routing.yml file the routes like this:
fstn_venice_homepage:
resource: "#FstnVeniceBundle/Resources/config/routing.yml"
prefix: /
fstn_venice_contact:
pattern: /contact
defaults: { _controller: FstnVeniceBundle:Contact:send }
I have enabled the prod env :$kernel = new AppKernel('prod', true);
Trying to execute the page on prod_env: http://localhost/fstn/web/app_dev.php/contact return an 404 error but in dev_env it displays the contact page correctly.
So that I try to debug the routes by: php app/console router:debug -e=prod
and I get this:
Name Method Scheme Host Path
fstn_venice_homepage ANY ANY ANY /
fstn_venice_contact ANY ANY ANY /contact
I even try to clear the cache by using the Command line :
php .\app\console cache:clear --env=prod --no-debug and it doesn't display any errors but no luck to display contact page on prod environment.
How can I fix this problem?
--edit---
I found the source of my error, actually I should use this path to work in prod env:http://localhost/fstn/web/app.php/contact but I used before http://localhost/fstn/web/contact to test.

Saying the kernel you want a prod environement $kernel = new AppKernel('prod', true); you tell him to forbid access to the dev url http://localhost/fstn/web/app_dev.php/contact.
If you want to access to the prod url, replace app_dev.php with app.php.
You can still let the kernel env configuration to dev, and test in prod environement. After every change, don't forget to clear your cache, and chmod it ;)

Clear your cache, It will be fine.

Related

symfony2 assets targets the /www server folder, not the /web symfony folder when deploy in production

I have some problems with Symfony 2 application deployment. I have import all files I need on my OVH shared server, but some errors occured like css and js files not found (internal server error for example) or error like Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://my-server/css/458dafd_bootstrap-theme.min_1.css".
Notice that I have installed the CoresphereBundle in order to have a console in my browser when my application is iploaded on my server, I have access to the console only on dev environment.
This is step by step what I did in order to deploy my application:
1 I updated my application and vendors with composer (because I have no ways to install composer on my server)
composer.phar update
2 I clear the dev cache php app/console cache:clear
3 I clear the prod cache php app/console cache:clear --env=prod --no-debug
4 I install assets php app/console assets:install web
5 I dump the assets php app/console assetic:dump web
6 I uploaded my symfony application on my server.
7 Once the files are uploaded in web/app.php I I authorize
the prod debug
$kernel = new AppKernel('prod', true);
8 Then in web/config.php I remove this block
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
So, on my server, if I would like to go to http://my-server/web/config.php it works well, so I see if my server is compatible with symfony. the only thing that appears is Set short_open_tag to off in php.ini*.
9 I set the access rights for the app/cache and app/log folders to 777 on my server, it allows the applications to write in these folders.
10 In web/app_dev.php I write this code, in order to allow the dev mode for my IP adress and so have access to the console bundle
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'121.457.719.2' //a random ip adress it's just for you to understand
))) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
11 So I have access to the dev environment on my server, all works well, and no errors occured here. To access to the console bundle, following to the bundle documentation, I have to wrote http://my-server/web/app_dev.php/_console (see the routing code here):
_console:
resource: "#CoreSphereConsoleBundle/Resources/config/routing.yml"
prefix: /_console
But this routes does not exist, If I wrote this url, nothing appear in my browser:
However, by the config.php, I have access to app_dev.php by following the Bypass configuration and go to the Welcome page link:
I click on the link and I arrived on app_dev.php. Like I said before, no errors occured in this environment, except for the console route. But I could have access to the console by clicking on the console logo under the symfony debug toolbar:
This is the url for the console when I click on the logo under symfony debug toolbar: http://my-server/web/app_dev.php//_console/_console, I would like to understand why?
Then when I would like to make some commands another error occured: [error] Internal Server Error in the console:
If I try to use the router debug php app/console debug:router, I have this:
and with the php app/console debug:router | grep _console:
So, there are the problems I have with my symfony application.
UPDATE
I resolved the problem of the console bundle. In fact my server does not use the same php version of my symfony application, I have to set this in the .ovhconfig at the root of my /www folder.
/www/.ovhconfig:
app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production
Now when I would like to access to the production environment I have these errors concerning all my assets files (css/js/images, a 404 not found):
Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/bundles/fosjsrouting/js/router.js
Uncaught ReferenceError: fos is not defined -> routing:1
Failed to load resource: the server responded with a status of 404 (Not Found)
->http://my-server.com/css/45898d_dataTables.min_7.css
I don't really understand, the files are indeed at the root of the app, e-g I have no folder css or js or etc in http://my-server.com/. These folders are in http://my-server.com/web/. Where is the problem?
When I access to the console, this is the command I made:
1 cache:clear
2 assets:install web
3 assetic:dump web
EDIT: solution works
I understand that the assets target a /css /js /images etc folder at the root of my server, so I replace the css and js files to the root of the /www server folder, e-g in the /www folder of my server I have this:
//my server
/.ssh
/www /*http://my-server.com/...*/
/app/
/bin/
/css/
/fonts/
/images/
/js/
/src/
/vendor/
/web/
/.htaccess
/.ovhconfig
/composer.json
/composer.lock
/composer.phar
Why my symfony application tagets the assets here?
Have you tried to use the Symfony command line routing debugger?
php app/console debug:router
That will output all the routes the symfony app knows about and you could try piping it into grep to see if you're trying to use the wrong path to hit the _console route.
php app/console debug:router | grep _console

Symfony 2: "No route found for "GET /" - error on fresh installation

I am trying to begin my education of symfony 2 and started with it's tutorial. One of first things I tried was to install symfony 2 and configure it.
When I try to access http://127.0.0.1:8000/, I am getting an incomplete site with the following error:
ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /"" at /home/spectator/webprojects/cls/app/cache/dev/classes.php line 2059
Things I have tried so far:
clearing cache (php app/console cache:clear --env=prod --no-debug)
recursively changing permissions to folder cls (symfony 2 folder) to
775 and even 777 (for diagnostics purposes)
adding "/" route to routing.yml and routing_dev.yml
reinstalling and
re-chmod symfony 2.
Try http://localhost:8000/app/example
Fresh installation has no routes for the root path "/"
first you need to set a default route
edit the routing.yml
app/config/routing.yml
app:
resource: #AppBundle/Controller/ # bundle name / Controller name
type: annotation # type of routing or
# app/config/routing.yml # file routing
app:
resource: #AppBundle/Controller/
prefix: /
you can learn more in http://symfony.com/doc/current/book/routing.html
The default installation does not come with a default route for "/".
The example controller only defines a route of
#Route("/app/example", name="homepage")
In the past, a fresh Symfony installation also included some simple demo code to learn how does the framework work. A few months ago we decided to change this behavior by the following:
A fresh Symfony installation no longer contains any demo code.
A new "Symfony Demo Application" has been published for people learning the framework (read more about this demo application).
If you use the Symfony Installer, you should do the following:
When learning Symfony, execute the symfony demo command
When creating a new Symfony project, execute the symfony new my_project command
I had the same problem. Just add <?php in the top of the file. Looks like if we don't specify it s

Symfony2 - prod environment doesn't work (page 404)

I have problem with my Symfony2 project. I created new bundle using console, but default controller is avalible only from dev environment level.
For
http://localhost/myproject/web/app_dev.php/hello/ZaqU
everything works fine, but for
http://localhost/myproject/web/app.php/hello/ZaqU
i'm redirecting on
http://localhost/myproject/web/hello/ZaqU
and then i getting only page 404.
This is new bundle and i didn't changed default files so I don't understand why it doesn't work. Files:
/* #FILE: app/AppKernel.php */
$bundles = array(
//...
new ZaqU\TestBundle\ZaqUTestBundle(),
);
.
/* #FILE: app/config/routing.yml */
ZaqU_test:
resource: "#ZaqUTestBundle/Resources/config/routing.yml"
prefix: /
Have you tried to clear your prod cache? Run the following command in the console:
./app/console cache:clear --env=prod
You might have not enabled the production environment in web/app.php. Change the false into true.
$kernel = new AppKernel('prod', true);
Hope this helps.
Cheers!

Symfony2 - Attempting to view my site in prod environment results in a blank screen; no errors/warnings in dev

Cross-posted from the official Symfony Google Group because time is an issue:
I'm in the final push to upload my site to my host. Everything runs fine in the dev environment - no errors, no warnings. When I attempt to access it in prod (localhost/web/app.php/), I get a blank screen. I attempted to clear the cache, to see if that would help, but got the following error:
$ app/console cache:clear --env=prod
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The parameter "kernel.trusted_proxies" must be defined.
I can clear the dev cache without issue.
Please help.
You'll need to add trusted_proxies to your config, even if it is blank.
Within: app/config/config.yml add:
framework:
trusted_proxies: ~
You'll also likely want to delete your cache files (app/cache/prod) and then run your console cache clear ($ app/console cache:clear --env=prod)

request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /"

I have installed Symfony2, after fixing the file permissions, I can access the dev environment from my browser by pointing it to:
http://localhost/app_dev.php
However, when I try to access the production environment by pointing the browser to http://localhost, I get the following exception (from app/logs/prod.log):
[2012-08-13 11:30:03] request.ERROR:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route
found for "GET /" (uncaught exc eption) at
/path/to/frameworks/Symfony2/app/cache/prod/classes.php line 4584 []
[]
I then checked the available routes for the prod environment from the command line. here is the result of that investigation.
root#yourbox:~/path/to/frameworks/Symfony2$ php app/console
router:debug -e=prod [router] Current routes Name Method Pattern
Incredibly, it shows that there are no routes defined for this environment (I didn't believe the error message - which essentially said the same thing).
So, my conclusion is this: out of the box installation of Symfony2, and the production environment has no default routes - is this true, or have I made a mistake somewhere?
More importantly, how do I fix this?. In SF1.x, it was straight forward to switch from dev to prod and vice versa. How do I view the AcmeDemo app for example, in a prod environment. ?
[[UPDATE]]
After feedback from thecatontheflat, I added a simple test route to my routing.yml file. The contents of app/config/routing.yml are now:
_welcome2:
pattern: /test
defaults: { _controller: AcmeDemoBundle:Welcome:index }
When I try http://localhost/test in the browser, I get the same 404 error. When I debug the routes available at the console, I get the following output:
root#yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod
[router] Current routes
Name Method Pattern
_welcome2 ANY /test
I had the exact same problem!!
Symfony2 has two generic routing files called:
app/config/routing.yml and app/config/routing_dev.yml
However, it also has a bundle specific routing file in each bundle. The standard procedure is to define all of your bundle routes in your bundle routing.yml file then reference this from the main routing.yml file by adding:
YourbundlenameMainBundle:
resource: "#YourbundlenameMainBundle/Resources/config/routing.yml"
prefix: /
This is what I had and I was still getting the error. But then I read the error more closely... no route found for GET / .... then I checked my routing_dev.yml file and of course it had a route for / from the Acme demo bundle _welcome route. This is why it works for the dev version but not the prod version!
Solution:
Add a route for / to either your routing.yml global file or your routing.yml bundle file by adding the following:
_welcome:
pattern: /
defaults: { _controller: YourbundlenameMainBundle:Default:index }
you can change index to some other route if your welcome page is not index
After you make sure you have your / route defined in any of your routing.yml
_welcome:
pattern: /
defaults: { _controller: YourbundlenameMainBundle:Default:index }
clear your prod environment cache!
app/console cache:clear --env=prod
I had the exact same problem. And it was caused because of a missing bundel in the AppKernel.php.
A little late but you might try to change this line in the web/app.php:
$kernel = new AppKernel('prod', false);
to:
$kernel = new AppKernel('prod', true);
That will enable debugging and you should be able to find your problem. When fixed you will ofcorse need to change it back to false ;).
Hope this helps.

Categories