Symfony 4 - Getting Started in 1 minute! (short tutorial)

Last updated at 2

Never neglect to upgrade Symfony, PHP, and other soft, that you use, to their latest stable versions! It helps to improve the speed of your app, avoid security issues and, finally, it allows to use new features.

Install

Create a project

There are two ways to create a Symfony 4 project. The difference is in the composer.json files below, and more precisely in the installed bundles.

For small apps, APIs, microservices, console applications etc.

$ composer create-project symfony/skeleton project_name

composer.json

"require": {
    "php": "^7.1.3",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "symfony/console": "...",
    "symfony/dotenv": "...",
    "symfony/flex": "...",
    "symfony/framework-bundle": "...",
    "symfony/yaml": "..."
}

 

For traditional web applications.

$ composer create-project symfony/website-skeleton project_name

composer.json

"require": {
    "php": "^7.1.3",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "sensio/framework-extra-bundle": "...",
    "symfony/asset": "...",
    "symfony/console": "...",
    "symfony/dotenv": "...",
    "symfony/expression-language": "...",
    "symfony/flex": "...",
    "symfony/form": "...",
    "symfony/framework-bundle": "...",
    "symfony/http-client": "...",
    "symfony/intl": "...",
    "symfony/monolog-bundle": "...",
    "symfony/orm-pack": "*",
    "symfony/process": "...",
    "symfony/security-bundle": "...",
    "symfony/serializer-pack": "*",
    "symfony/swiftmailer-bundle": "...",
    "symfony/translation": "...",
    "symfony/twig-bundle": "...",
    "symfony/validator": "...",
    "symfony/web-link": "...",
    "symfony/yaml": "..."
},
"require-dev": {
    "symfony/debug-pack": "*",
    "symfony/maker-bundle": "...",
    "symfony/profiler-pack": "*",
    "symfony/test-pack": "*",
    "symfony/web-server-bundle": "..."
}

 

Run Symfony local web server (as WebServerBundle)

If you created symfony/skeleton project, you don't have web server bundle. First, run:

$ composer require symfony/web-server-bundle --dev

Then start it:

$ php bin/console server:run

    [OK] Server listening on http://127.0.0.1:8000

That's all! The bundle shows logs right here - in your console, so you can just open a new one for commands.

Or, you can download more powerful Symfony Local Web Server - read docs here

Ready to start!

Open http://127.0.0.1:8000, or another URL that you received after starting the server, you should see

Welcome to Symfony 4

 


Comments

No comments yet. Be the first!)

Leave a comment

Guest