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:
- clone git repo with my application on the production server
- installed composer dependencies
- migrated database structure
- updated env with new db connection
3
Answers
I hope auto wire is enabled in service.yaml
And please comment code in routes.yaml
And try with
php bin/console cache:clear
command.try with PHP 8 attributes
function:
Documentation:
https://www.php.net/manual/fr/language.attributes.overview.php
You must require:
After that just change FollowSymLinks to SymLinksIfOwnerMatch … and "vu à la" … This package reconfigure Your code for Apache web-server …