skip to Main Content

I know this question has been discussed million times here, but it is the third day I keep on struggling on this issue.

I’ve got symfony application been developed on my local PC (Windows). Now I’m trying to deploy it on my linux web-hosting (Linux).

My routes are initted in controllers’ classes via annotations.

<?php

namespace AppController;

use AppEntityCategory;
use AppRepositoryCategoryRepository;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;

class IndexController extends AbstractController
{
    /**
     * @Route("/", name="app_index")
     */
    public function index(): Response
    {
        return $this->render('index/index.twig', [
            'controller_name' => 'IndexController'
        ]);
    }
}

The issue is these routes are not included by some reason, which leads to 404 error

/config/services.yaml

services:
  _defaults:
    autowire: true
    autoconfigure: true

  App:
    resource: '../src/'
    exclude:
      - '../src/DependencyInjection/'
      - '../src/Entity/'
      - '../src/Kernel.php'
...

/config/routes/annotations.yaml

controllers:
    resource: ../../src/Controller/
    type: annotation
    prefix:
      ru: '' # don't prefix URLs, the default locale
      en: '/en'

kernel:
    resource: ../../src/Kernel.php
    type: annotation

/config/routes.yaml is empty

symfony console debug:router shows only admin and profiler routes but not mine initted in controllers

I would be very grateful if you could help me solving this issue.

If I describe the index route in routes.yaml (which I don’t like.. What are the annotations then for?)

index:
    path: /
    controller: AppControllerIndexController::index

symfony goes wild
"AppControllerIndexController" has no container set, did you forget to define it as a service subscriber?

All I’ve done during deployment was:

  1. clone git repo with my application on the production server
  2. installed composer dependencies
  3. migrated database structure
  4. updated env with new db connection

3

Answers


  1. I hope auto wire is enabled in service.yaml

    services:
        # default configuration for services in *this* file
        _defaults:
            autowire: true      # Automatically injects dependencies in your services.
            autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    

    And please comment code in routes.yaml
    And try with php bin/console cache:clear command.

    Login or Signup to reply.
  2. try with PHP 8 attributes

    #[Route('/', name: 'app_index')]
    

    function:

    #[Route('/', name: 'app_index')] 
    public function index(): Response {
        return $this->render('index/index.twig');
    }
    

    Documentation:

    https://www.php.net/manual/fr/language.attributes.overview.php

    Login or Signup to reply.
  3. You must require:

    composer require symfony/apache-pack
    

    After that just change FollowSymLinks to SymLinksIfOwnerMatch … and "vu à la" … This package reconfigure Your code for Apache web-server …

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search