Search code examples
phpsymfonyweb-deployment

Symfony 5 : Error - No route found for "GET /<SiteConfigAcces>"


I developped a site with sympfony/phpp i want to deploy on a local server.

After the development on my own computer (where it works well), I put the project on a local server with apache, php 7.3.x, composer 2.0.0 under a debian 10 OS

All the transfer of the project from my computer to the server and the setting are well finished. The project folder name is si2a. It is in the directory /var/www I set the permissions access on this directory with ACL following a symfony doc guideline.

I set the site configuration file those the name is si2afama.conf. This last is in the directory /etc/apache2/sites-available. After setting, I activate the site, reload apache and clear the cache. Here is the si2afama.conf's contain :

<VirtualHost *:80> 
    ServerName si2afama 
    # ServerAlias www.si2afama.com 
 
    DocumentRoot /var/www/si2a/public
    DirectoryIndex /index.php
 
    <Directory /var/www/si2a/public> 
        AllowOverride All 
        Require all granted
        Allow from All 
 
    FallbackResource /index.php
 
    </Directory>
 
    <Directory /var/www/si2a/public/bundles>
        FallbackResource disabled
    </Directory>
 
    ErrorLog /var/log/apache2/si2a_error.log
    CustomLog /var/log/apache2/si2a_access.log combined 
</VirtualHost>

When i try to access the site, i found this error : No route found for "GET /si2afama"

Since, it is a Routing issus, here are some files's contain :

si2a/config/packages/routing.yaml

framework:
    router:
        utf8: true

si2a/config.routes.yaml

index:
    path: /
    controller: App\Controller\DefaultController::index

si2a/public/index.php.

<?php
use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
    umask(0000);
    Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

I don't really know what to do in order to fix the issus.

May someone help me, please. Thank you.


Solution

  • Your vhost is related to your domain name and directory of source code, if you want a route name like si2afama for your application, you have to add it to symfony routes.

    # si2a/config.routes.yaml
    
    
    index:
        path: /
        controller: App\Controller\DefaultController::index
    
    si2afama:
        path: /si2afama
        controller: App\Controller\DefaultController::nameActionFromController