-->

Symfony 404 not found

2019-05-15 03:59发布

问题:

I'm new to symfony.

I did:

rm -rf app/cache/*
rm -rf app/logs/*

Then:

sudo setfacl -R -m u:www-data:rwx -m u:user :rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:user:rwx app/cache app/logs

ls -al gives:

drwxrwxrwx 3 user user  1024 мая   29 00:06 cache(cache is on green background)
drwxrwxrwx 2 user user  1024 мая   29 00:06 logs(logs is on green background)

Now i'm trying to access /Symfony/web/app_dev.php - It shows:

An error occurred while loading the web debug toolbar (404: Not Found).

Do you want to open the profiler?

When i click OK, it redirect to

/Symfony/web/app_dev.php/_profiler/bd8604738ac7af3c9d0611ea12076f0f62422601

and 404 file not found..

This is app/logs/dev.log

[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-05-29 00:12:29] request.INFO: Matched route "_welcome" (parameters: "_controller": "Acme\DemoBundle\Controller\WelcomeController::indexAction", "_route": "_welcome") [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DeprecationLoggerListener::injectLogger". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []

I've not found an solution, please help

Edit:

Routing_dev.xml

_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

_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

config_dev.xml

imports:
    - { resource: config.yml }

framework:
    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        firephp:
            type:  firephp
            level: info
        chromephp:
            type:  chromephp
            level: info

assetic:
    use_controller: true

#swiftmailer:
#    delivery_address: me@example.com

app_dev.php

<?php

use Symfony\Component\HttpFoundation\Request;

// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

回答1:

My problem was that kernel.terminate event was executing for more than 10 seconds. It was very hard to spot, because profiler was not measuring timeline for this event.

When I realised this, I immediately narrowed the problem down to one of my event listeners having abnormally long running __construct method. This delayed profile file printing for too long, which caused a Javascript timeout error after 5 retries.

After fixing the offending listener, kernel.terminate event went fast and the problem was gone immediately.

You can quickly see your attached listeners using bin/console debug:event-dispatcher kernel.terminate.



回答2:

According to my own experience; this behavior happens when you change the standard behavior of your routes. For example, in my case I was using kernel.request listener to create a language detection mechanism which supposed pick the best possible language for the user based on her/his browsers supported language.

I was using {_locale} prefix in all my routes located in app/config/routing.yml

some_route:
    resource: "@MyBundle/Resources/config/routing.yml"
    prefix:   /{_locale}/

This way I was able to quickly add at the beginning of my routes the language code and in my listener class I was redirecting the client to a route prefixed with an existing language code regardless the client requested the route with or without the locale.

For example, if my site had only "en" and "de" as languages and if the user requested

http://www.mysite.com/somepage

or

http://www.mysite.com/fr/somepage

I was redirecting the client to

http://www.mysite.com/en/somepage

So whenever there was an error in my application the profiler route was unaware of this situation and was trying to show itself from a route that has no {_locale} prefixed. And this was causing a 404 error.

The solution was simple:

I opened the app/config/routing_dev.yml file and modified the all the routes as below:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /{_locale}/_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /{_locale}/_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /{_locale}/_configurator

Notice the /{_locale} part.

So the problem is fixed for me.



回答3:

What ended up working for me was increasing the values for memory_limit and max_execution_time in my php.ini file, restarting php-fpm (e.g., brew services restart php56), and then restarting the server (sudo nginx -s reload). If it still doesn't work after all of that, try restarting your computer. It worked for a coworker of mine.



回答4:

Perhaps you haven't included the routes for the web profiler?

If you post your config_dev.yml & routing_dev.yml maybe we can see what is wrong.

Your routing_dev.yml should look something like this

_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

Your config_dev.yml should contain this

imports:
    - { resource: config.yml }
    - { resource: security_dev.yml }

framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"

Also make sure app_dev.php is setting the environment to dev like so

// ...
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
// ...


回答5:

In my case it was a route conflict . I changed the routes in routing_dev.yml in a way that is not in conflict with my routes