9951 explained code solutions for 126 technologies

php-symfonyHow to create a backend with PHP Symfony?

Creating a backend with PHP Symfony is easy and straightforward.

Install the Symfony framework:

$ composer create-project symfony/website-skeleton my-project

Create a controller:


namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;

class DefaultController
    public function index()
        return new Response('Hello World!');

Create a route:

# config/routes.yaml

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

Start the server:

$ cd my-project
$ symfony server:start

Visit the page:


You should now see the "Hello World!" message.

Helpful links

Edit this code on GitHub