Few steps to do after creating a Symfony 6 application
Disclaimer: What I say here applies to me, and the purpose is to share that, because it can help other.
Installing a new Symfony 6 application
I use to create Symfony applications with the Symfony CLI.
I issue:
symfony new my_application
At the present time (January 2022), it installs a version 6.0.2 one
Running the new application
After installing, I use to create a Controller and try to Respons a simple JSON like this
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends AbstractController
{
public function index(): Response
{
return $this->json(["OK"]);
}
}
It does almost nothing, but it make me confident on the basic that works.
Create the route
I use to use "routes.yaml" to define and enumerate my routes, but nowadays default creation is configured to use "annotations"
So, because it is OK for me to follow the defaults, I edit my controller to use annotations:
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/")
*/
public function index(): Response
{
return $this->json(["OK"]);
}
}
But this doen't work yet, I need to perform one last step: installing "annotations"
This is done with
composer require doctrine/annotations
Conlusion
To summarize, in order to fire-up a Symfony application, we need to:
symfony new my_application cd my_application composer require doctrine/annotations symfony server:start --no-tls