Report this

What is the reason for this report?

Routing doesn`t work - Symfony app

Posted on March 22, 2020

Hi,

I am trying to deploy my Symfony app to the Digital Ocean. The problem is with routing - the app cannot find my annotation routes in the Controller, so on requesting http://104.248.16.246/ the response is default Symfony homepage.

My dev.log is :

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException:                                                                                                       "No route found for "GET /"" at /var/www/coinwatch/vendor/symfony/http kernel/EventListener/RouterListener.php line 136                                                                                                                     {"exception":"[object (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /\" at /var/www/coinwatch/vendor/symfony/http-kernel/EventListener/RouterListener.php:136)\n                    [previous exception] [object] (Symfony\\Component\\Routing\\Exception\\NoConfigurationException(code: 0):  at /var/www/coinwatch/vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php:182)"} [] 

I have been following this guide https://www.digitalocean.com/community/tutorials/how-to-deploy-a-symfony-4-application-to-production-with-lemp-on-ubuntu-18-04

My source code (app is working correctly on my localhost) [https://github.com/holesa/coinWatch]

Here is my server block config file

server {
    listen 80;
    listen [::]:80;

    server_name coinwatch 104.248.16.246;
    root /var/www/coinwatch/public;
    index index.php;
    client_max_body_size 100m;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
      }

    location ~ /\.(?:ht|git|svn) {
        deny all;
    }
}

On command

php bin/console debug:router 

it returns no routes

Thanks in advance.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Accepted Answer

Finally, I have fixed it. The problem was apparently in outdated composer packages. This command worked.

composer update --with-dependencies 

Initially, the previous command was failing because of lacking swapping memory. That was fixed by following commands.

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

Since you say it works locally, my best guess would be a caching problem. Go and check /var/www/coinwatch/var/cache - does it have the proper permissions?

You can also try running bin/console cache:clear -vvv on the droplet and see what happens, perhaps the cache isn’t being generated properly.

Also check your codebase for hardcoded paths.

P.S. Why do you have a var/log folder inside public? Is that a custom thing, or is Symfony creating it? The var folder should generally be outside of public.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.