This tutorial has a new version, check it out!

Symfony 4: Let's Launch!

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Hey guys! Yes! It's Symfony 4 time! I am so excited. Why? Because nothing makes me happier than sitting down to work inside a framework where coding is actually fun, and where I can build features fast, but without sacrificing quality. Well, maybe I'd be even happier doing all of that on a beach... with, maybe a cold drink?

Anyways, Symfony 4 completely re-imagined the developer experience: you're going to create better features, faster than ever. And, Symfony has a new, unique super-power: it starts as a microframework, then automatically scales in size as your project grows. How? Stay tuned...

Oh, and did I mention that Symfony 4 is the fastest version ever? And the fastest PHP framework? Honestly, all frameworks are fast enough anyways, but the point is this: you're building on a seriously awesome foundation.

Tip

See http://www.phpbenchmarks.com for the third-party benchmark stats!

Prep: Download & Update Composer

Ok, let's get started already! Open a new terminal and move into whatever directory you want. Make sure that you already have Composer installed globally so that you can just say composer. If you have any questions, ask us in the comments!

And also make sure you have the latest version:

composer self-update

That's important: Composer had a recent bug fix to help Symfony.

Install Symfony!

To download your new Symfony project, run composer create-project symfony/skeleton and put this into a new directory called the_spacebar.

composer create-project symfony/skeleton the_spacebar '4.4.*'

That's the name of our project! "The Spacebar" will be the place for people from across the galaxy to communicate, share news and argue about celebrities and BitCoin. It's going to be amazing!

This command clones the symfony/skeleton project and then runs composer install to download its dependencies.

Further down, there's something special: something about "recipes". OooOOO. Recipes are a new and very important concept. We'll talk about them in a few minutes.

Starting the Web Server

And at the bottom, cool! Symfony gives us clear instructions about what to do next. Move into the new directory:

cd the_spacebar

Apparently, we can run our app immediately by executing:

php -S 127.0.0.1:8000 -t public

This starts the built-in PHP web server, which is great for development. public/ is the document root of the project - but more on that soon!

Tip

If you want to use Nginx or Apache for local development, you can! See http://bit.ly/symfony-web-servers.

Time to blast off! Move to your browser and go to http://localhost:8000. Say hello to your new Symfony app!

Our Tiny Project

Tip

Symfony no longer creates a Git repository automatically for you. But, no problem! Just type git init once to initialize your repository.

Back in the terminal, I'll create a new terminal tab. Symfony already inititalized a new git repository for us and gave us a perfect .gitignore file. Thanks Symfony!

Tip

If you're using PhpStorm, you'll want to ignore the .idea directory from git. I already have it ignored in my global .gitignore file: https://help.github.com/articles/ignoring-files/

That means we can create our first commit just by saying:

git init
git add .
git commit

Create a calm and well-thought-out commit message.

# Woohoo! OMG WE ARE USING SYMFONY4

Woh! Check this out: the entire project - including Composer and .gitignore stuff - is only 16 files! Our app is teenie-tiny!

Let's learn more about our project next and setup our editor to make Symfony development amazing!

Leave a comment!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1", // v5.1.3
        "symfony/asset": "^4.0", // v4.0.3
        "symfony/console": "^4.0", // v4.0.14
        "symfony/flex": "^1.0", // v1.2.7
        "symfony/framework-bundle": "^4.0", // v4.0.14
        "symfony/lts": "^4@dev", // dev-master
        "symfony/twig-bundle": "^4.0", // v4.0.3
        "symfony/web-server-bundle": "^4.0", // v4.0.3
        "symfony/yaml": "^4.0" // v4.0.14
    },
    "require-dev": {
        "easycorp/easy-log-handler": "^1.0.2", // v1.0.4
        "sensiolabs/security-checker": "^5.0", // v5.0.3
        "symfony/debug-bundle": "^3.3|^4.0", // v4.0.3
        "symfony/dotenv": "^4.0", // v4.0.14
        "symfony/monolog-bundle": "^3.0", // v3.1.2
        "symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.3
        "symfony/profiler-pack": "^1.0", // v1.0.3
        "symfony/var-dumper": "^3.3|^4.0" // v4.0.3
    }
}