Symfony2 MethodNotAllowedHttpException on live ser

2020-04-02 10:58发布

问题:

I am getting below error on live server:

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "GET user/create: Method Not Allowed (Allow: POST)" at /home/public_html/project/app/cache/prod/classes.php line 3685

but I am not getting this error on a local machine with the same code.

Solutions points to clearing the cache, but I am not able to get how we can clear cache on a live server.

I also deleted cache folder from live server, but the issue still persists.

UPDATE: The issue is surprisingly solved after updating base.html.twig file. i think cache regenerates again with some dependencies after that. but still i did not get how it is resolved as deleting cache folder does not resolved it but changes in base.html.twig file does the job.

回答1:

Try to run php app/console router:debug | grep user/create to check if this route loaded at all. Maybe you load this route only for specific env.



回答2:

It's because you have to call you route with "POST method. Try to remove @Method("POST") in you controller or Add GET with @Route("GET","POST"). Documentation

Or try this following command :

php app/console cache:clear -e prod

Otherwise, delete app/cache folder.



回答3:

Try

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

chmod 777 app/cache/
chmod 777 app/logs/

If problem solved, read more in "Setting up Permissions" section: http://symfony.com/doc/current/book/installation.html