How to create a Symfony project

A new Symfony project starts as a Composer-managed directory with the framework kernel, configuration tree, public front controller, and development tooling that later features build on. Creating the project with the Symfony CLI is the shortest current path when a developer wants a full web application skeleton rather than only the minimal framework package.

The --webapp option installs the common web application dependencies during creation, including routing, Twig, forms, Doctrine, Messenger, Mailer, and development bundles used by typical Symfony applications. Use the latest stable release for new feature work, or pass a version option only when a project has an explicit LTS or compatibility requirement.

The local smoke check uses a temporary controller so the created project proves both the console bootstrap and the HTTP request path. Remove the smoke controller after the check, then create the real controllers and routes that belong to the application.

Steps to create a Symfony project:

  1. Open a terminal in the parent directory where the project folder should be created.
  2. Create the Symfony web application project.
    $ symfony new acme-app --webapp --no-git
    * Creating a new Symfony project with Composer
    
     [OK] Your project is now ready in /srv/acme-app

    Omit --no-git when the new project should be initialized as a Git repository. Use a project name that matches the real application directory.

  3. Enter the project directory.
    $ cd acme-app
  4. Confirm the generated project boots through Symfony Console.
    $ php bin/console about
     -------------------- --------------------------------- 
      Symfony                                               
     -------------------- --------------------------------- 
      Version              v8.1.0                           
      Long-Term Support    No                               
      Environment          dev                              
      Debug                true                             
     -------------------- --------------------------------- 
      PHP                                                   
     -------------------- --------------------------------- 
      Version              8.5.4                            
      OPcache              Enabled                          
     -------------------- --------------------------------- 

    The exact Symfony and PHP versions depend on the installed runtime and the currently stable release.

  5. Create a temporary smoke controller for the HTTP check.
    ProjectSmokeController.php
    <?php
     
    namespace App\Controller;
     
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Attribute\Route;
     
    final class ProjectSmokeController
    {
        #[Route('/project-smoke', name: 'project_smoke')]
        public function __invoke(): Response
        {
            return new Response('Symfony project is running.');
        }
    }

    Save this file as src/Controller/ProjectSmokeController.php. Permanent page and endpoint controllers belong in their own application-specific classes.
    Related: How to create a Symfony controller
    Related: How to create a Symfony route

  6. Confirm the temporary route is registered.
    $ php bin/console debug:router project_smoke
    +--------------+---------------------------------------------------------+
    | Property     | Value                                                   |
    +--------------+---------------------------------------------------------+
    | Route Name   | project_smoke                                           |
    | Path         | /project-smoke                                          |
    | Defaults     | _controller: App\Controller\ProjectSmokeController()    |
    +--------------+---------------------------------------------------------+
  7. Start the local Symfony web server in the background.
    $ symfony server:start --no-tls --port=8000 -d
    
     [WARNING] The local web server is optimized for local development and MUST never be used in a production setup.
    
     [OK] Web server listening
          The Web server is using PHP CLI 8.5.4
          http://127.0.0.1:8000

    The Symfony local server is for development only. Do not expose it as a production web server.

  8. Request the smoke route.
    $ curl --silent --show-error --include http://127.0.0.1:8000/project-smoke
    HTTP/1.1 200 OK
    Content-Type: text/html; charset=UTF-8
    X-Powered-By: PHP/8.5.4
    ##### snipped #####
    
    Symfony project is running.

    HTTP 200 OK and the response text confirm the project can handle a request through the Symfony kernel.

  9. Stop the local server.
    $ symfony server:stop
    Stopping PHP
    Stopping Web Server
    
     [OK] Stopped 2 process(es) successfully
  10. Remove the temporary smoke controller.
    $ rm src/Controller/ProjectSmokeController.php

    Keep the project directory and generated dependencies; only the temporary proof controller is removed.