Symfony 4: Let's Launch!

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

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! 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!

  • 2018-12-12 Victor Bocharsky

    Glad you got it working, great job!

    Cheers!

  • 2018-12-12 Dennis

    Hi Victor,

    Thanks for your quick reply.

    I figured it out it had something to do with my PHP version, because when I wanted to upgrade to symfony 4, there was a warning. So I downloaded the correct PHP version, changed my environment variables in Windows and it worked.

    Thanks.

    Best regards,
    Dennis

  • 2018-12-12 Victor Bocharsky

    Hey Dennis,

    It depends on your PHP version, Symfony 4 requires PHP ^7.1.3. If you have a lower version of PHP, Composer will resolve dependencies and install Symfony 3.4.

    You can check your PHP version with this command:
    $ php --version

    Cheers!

  • 2018-12-12 Dennis

    Hey Ryan,

    When I run the command "composer create-project symfony/skeleton name_of_project" it installs version 3.4.20.
    How is this possible and how can I upgrade to symfony 4?

    Best regards,
    Dennis

    P.S. I did run composer self-update before installing the project.

  • 2018-10-12 Victor Bocharsky

    Hey Pawel,

    Both work great, because those libs are frontend part, but Symfony is a backend. With Webpack Encore you can organize both libs pretty well in your Symfony project. Though, it depends what's the best for you. It depends on the project and the tasks you need to implement.

    P.S. We don't have a screencasts about VueJS yet, but we do have ReactJS one, so you can look at it and see if it completely fits your needs:
    https://symfonycasts.com/sc...

    Cheers!

  • 2018-10-12 Paweł Chry

    Hi guys, please help me choose js library for my team. It's about ReactJS or Vue. With one work better with Twig and Symfony?

  • 2018-10-02 Guilherme Billig

    Thank you

  • 2018-10-02 Victor Bocharsky

    Hey Guilherme,

    Ah, you probably have old version of PHP. Symfony 4 requires PHP 7.1.3 at least, see https://github.com/symfony/... . What version of PHP do you use? You can check it with:
    $ php --version

    Cheers!

  • 2018-10-02 Guilherme Billig

    Hi, why i get Symfony 3.4.16 when i start this project? (I am really new at this) Can I attend classes without having problems with version?

  • 2018-09-25 El Tebe

    +1

    And don't forget: Maybe your paths and links should not work if your windows username (personal folder path) contains extra characters, like UTF8 éáűőúöüóß, whitespace, etc... then U must use a lot of " and/or ' and escape characters.

  • 2018-09-25 Adiel Cristo

    Hi,

    Also, avoid creating things on C:\Windows, as it is one of the main system folders, and you could screw up the system. That's why you need admin permissions to make changes there.

    It's better to create the project on a personal folder where you already have the permissions.

    Cheers!

  • 2018-09-24 Diego Aguiar

    Hey Maxim Mandrik

    I believe Ryan just ignored "src/Controller/.gitignore" ;)

    Cheers!

  • 2018-09-24 Maxim Mandrik

    I checked in the project 17 files, not 16.

    $ git status
    new file: .env.dist
    new file: .gitignore
    new file: bin/console
    new file: composer.json
    new file: composer.lock
    new file: config/bundles.php
    new file: config/packages/dev/routing.yaml
    new file: config/packages/framework.yaml
    new file: config/packages/routing.yaml
    new file: config/packages/test/framework.yaml
    new file: config/packages/test/routing.yaml
    new file: config/routes.yaml
    new file: config/services.yaml
    new file: public/index.php
    new file: src/Controller/.gitignore
    new file: src/Kernel.php
    new file: symfony.lock

  • 2018-09-04 weaverryan

    Good tip El Tebe! Thanks for sharing :)

  • 2018-09-04 El Tebe

    If U get somthing like this: "Warning: unlink(XXXXXXX/var/cache/dev/ContainerHz2YWDR.legacy): No such file or directory"
    just set this directive to zero: xdebug.scream = 0 (in your php.ini)
    See this: https://stackoverflow.com/q...

  • 2018-09-03 Victor Bocharsky

    Hey Raman,

    Ah, really, good catch! The "-t" option is missing :)

    And thank you for pointing about it in such an old thread!

    Cheers!

  • 2018-09-01 Raman Paul

    Old thread but for new users stumble across this , it should be
    `$ php -S 127.0.0.1:8000 -t public`

    Switch `-t` is missing in above comment.

  • 2018-08-09 weaverryan

    Hey Irfan!

    Hmm, can you try it again? It works fine for me now - we use Vimeo as our backend, and my guess is that they had some sort of temporary issue. Annoying - sorry about that :/. If it's still not working, definitely let me know!

    Cheers!

  • 2018-08-08 Irfan

    I got this " The media could not be loaded, either because the server or network failed or because the format is not supported.
    " on playing video. I am using windows 10 with chrome. Other videos work perfectly fine

  • 2018-08-06 Victor Bocharsky

    Hey Priya,

    Thank you for kind words! About your question - well, it depends on your OS. Looks like you're on Windows OS, and this OS is well-known as OS with a pretty bad command line, that is slightly different from command line used in Linux/Unix systems. I'm not on Windows, but I heard a lot of good feedbacks about Cmder - a console for Windows OS, see https://github.com/cmderdev... . I think it will fix your problem.

    Cheers!

  • 2018-08-05 Priya Rajarajan

    Hi,
    First of all a very big thanks for this wonderful tutorial.I'm here because for creating a dealer management system for my client.When I started researching ,I came to know about symfony .But didn't know where to start with.But luckily,I reached your website.Everything worked fine for me.But I have 1question
    1.As the other member had asked it was going fine till ,I initated the git in my command prompt,it showed unrecognized keyword.But when I,installed Git,it opened in a MINGW64 editor.Then I changed to my project location and executed the rest of the steps in the MINGW64 editor which went perfectly well.Still a small confusion even though the repository is in the same project location,why it is not still recognizing in command prompt?.May be a silly question,but as a novice I want to be clear if I travelling in the right path

  • 2018-07-10 Diego Aguiar

    Hey Siwar Bondka

    Look's like you do not have the right permissions for writing on your project's folder. I'm not sure how to properly adjust them in Windows, but I just found this guide.
    I hope it helps https://answers.microsoft.c...

    Cheers!

  • 2018-07-10 Siwar Bondka

    Hello
    This is what i ve got while Creating my new project:

    -------------------------------------------->>>>>>>>>>

    C:\Windows>composer create-project symfony/skeleton my-project
    Installing symfony/skeleton (v4.1.0)

    [ErrorException]
    mkdir(): Permission denied

    create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

    C:\Windows>
    C:\Windows>

    -------------------------------------------
    Help please

  • 2018-06-20 weaverryan

    Hey Daniel Rolfs!

    Ah, sorry about that! I know the problem! Recently, Symfony removed this feature where you have a Git repository automatically created for you. We'll update the video with a note. Now, you just need to type


    git init

    first to initialize the git repository.

    Cheers!

  • 2018-06-20 Daniel Rolfs

    Hi! everything worked fine, until i opend the new terminal tab and entered git status:

    fatal: Not a git repository (or any of the parent directories): .git

    what can i do?

  • 2018-04-16 Victor Bocharsky

    Hey Rafael,

    It works pretty straightforward, if HTML response contains closing body tag - the web debug toolbar adding some HTML/JS content before this closing body tag and that's why you see that toolbar. So, if your response does not contain closing body tag - you won't see it. Or... it just does not enable in configuration for your current environment :)

    Cheers!

  • 2018-04-14 Rafael Ferreira

    Hi Guys!

    Could you tell me, why the debug toolbar is not showing?

  • 2018-04-13 Victor Bocharsky

    Hey Petru,

    Nope, Symfony just initialize an empty repo for you, and then you can do with it whatever you want, for example, commit changes and push to GitHub, etc.

    Cheers!

  • 2018-04-13 Victor Bocharsky

    Hey Petru,

    Yeah, nice course to quickly join the topic and start with Git ;)

    Cheers!

  • 2018-04-12 Petru Lebada

    Pff... spoke too soon.I just read the git interactive course and it enlightened me.Thanks

  • 2018-04-12 Petru Lebada

    I'm also new to git and i was wondering if and how i can see the files i've commited on the repository.And what is the default repository that come with symfony? Can it be seen on github or?

  • 2018-04-09 Vlad

    This is wicked!

  • 2018-03-27 Victor Bocharsky

    Hey Barrosy,

    Thanks for sharing those links for our Windows users. Answering your question: yes, you have to install Git as well. Git is a free and open source distributed version control system. In other words, Git allow you to store snapshots of your changes you made in your project (it's called commits). So Git allow you to safely work in a team and preventing from overwriting each other unintentionally. Also it's useful even if your working on the project alone. There's a lot to say about Git, better to read their docs: https://git-scm.com/doc . You can also try to complete their free interactive course here: https://try.github.io/ . To install Git - go to their website and find the latest version for your OS: https://git-scm.com/ .

    In our Symfony-related screencasts we assume that users have some developer background, at least they know PHP / Composer / Git / PhpStorm and have it installed locally, because these things are really basic and it's difficult to move forward without it. If you have weak knowledges of PHP or Composer, we have specific courses about it, so you can check them out first:
    https://knpuniversity.com/t...
    https://knpuniversity.com/s...
    https://knpuniversity.com/s...

    Unfortunately, we don't have a course about Git, but like PhpStorm it's not required for Symfony courses but strongly recommended by us. And you can easily find information about it on the internet, Git is not complex at all and you need to know a very little to start using it.

    I hope it helps you and other devs.

    Cheers!

  • 2018-03-24 Barrosy

    Hello!

    I have a couple of questions to you good sir, as I am a complete novice to Symfony.
    First of all to those who are just like me, new to symfony, you want to make sure to install PHP beforehand as (a program required to install Symfony called) Composer requires you to have PHP installed. If you are a Windows user like me, then the following page (as of today, any url refered to in this post might change in the future), you should be able to install PHP from here: https://windows.php.net/dow...
    You can install it on the root of any of your disks available to you or you could make a folder called "programming" on any of your disks and save it there (for example: D:\programming\PHP\).

    Then you can install composer from here (as of today aswell): https://getcomposer.org/doc...

    Okay so here is my question: From 3 minutes and 15 seconds onward, you start talking about Git, but for someone like me who's entirely new to Symfony, what is Git actually? If I run the same command, my prompt will say that the command is not recognized, so I'd assume I would have to install that aswell? Anyways, I will try and figure, but I can imagine other people might encounter to have some trouble getting through here.

  • 2018-03-19 weaverryan

    Hey John!

    Oh man, lame! Let's see if we can get this working for you :). Here's the key error that looks weird to me:

    > PHP Fatal error: Unknown: Failed opening required 'public'

    This tells me that, somehow, after you move into your /var/www/tests/php/symfony/sf4/the_spacebar directory, there is NOT a public/ directory inside! That's definitely a mystery, but it gives us a place to start. So, if you look at your /var/www/tests/php/symfony/sf4/the_spacebar directory, what do you see inside? Is there a public directory?

    Cheers!

  • 2018-03-19 Victor Bocharsky

    Hey milosh96 ,

    Well, it depends, if you're going to work with a project which is on Symfony 3 - I'd recommend to start with Symfony 3 track then. But if you're going to start a new project from scratch - it's definitely better to start with Symfony 4. But since Symfony 4 is pretty new - we don't have a lot of screencasts about it, so probably after watching all our courses about Symfony 4 you can continue watching ones from Symfony 3 track, but of course, do them in Symfony 4 way because you'll know a lot about it after finishing Symfony 4 track.

    Cheers!

  • 2018-03-19 Victor Bocharsky

    Good point, thanks Alessandro Lai !

    Symfony really requires PHP 7.1.3 or higher. Check your PHP version with:

    php --version

    And upgrade it to the minimum required version if you want to use the latest Symfony 4.

    Cheers!

  • 2018-03-17 John

    Hi there,

    I have this issue :

    $ cd /var/www/tests/php/symfony/sf4/the_spacebar
    $ php -S 127.0.0.1:8000 public
    PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 Development Server started at Sat Mar 17 23:13:26 2018
    Listening on http://127.0.0.1:8000
    Document root is /var/www/tests/php/symfony/sf4/the_spacebar
    Press Ctrl-C to quit.
    [Sat Mar 17 23:13:37 2018] PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
    [Sat Mar 17 23:13:37 2018] PHP Fatal error: Unknown: Failed opening required 'public' (include_path='.:/usr/share/php') in Unknown on line 0

    I got this error running my browser to the 127.0.0.1:8000 url (it's a blank page).
    I check the permissions, the directories in vendor/, everything seems good, but... not enough to work. Why did the video run the server so easily, and not me ?

  • 2018-03-17 milosh96

    I have a good knowledge of Laravel 5>, and I want to learn (switch to) Symfony. I followed "Getting Started" guide for Symfony 4, but I'm wondering, is it better for a newbie (like me), to learn Symfony 3 first, and then switch to Symfony 4 later. What's your opinion? Thanks.

  • 2018-03-16 Alessandro Lai

    Symfony 4 requires PHP 7.1 or newer. Do you have it?

  • 2018-03-16 Diego Aguiar

    Hey @Arkadiusz

    I'm not sure why is that happening (I just tried it my self and it installed version 4.0.5). I believe you have to clear your composer's cache

    $ composer clearcache


    Give it a try and let me know if that worked

    Cheers!

  • 2018-03-16 Arkadiusz

    Why composer version
    composer --version
    Composer version 1.6.3 2018-01-31 16:28:17
    after use:
    composer create-project symfony/skeleton the_spacebar
    Installing symfony/skeleton (v3.4.5)

    Is downloading and instaling symfony version 3.4.5? I want minimum 4.0.4.

  • 2018-03-16 weaverryan

    No problem - I'm happy the mystery is solved :). I also noticed in the next patch version of Symfony, the welcome page will ALWAYS show if you don't have a homepage, even if you have other routes. So, it should fix this weird user-experience quirk.

    Cheers!

  • 2018-03-15 Victor Bocharsky

    Hey Tess,

    Glad you found the problem!

    Cheers!

  • 2018-03-15 Tess Hsu

    hi Victor,
    no worries, sorry it was my falut, I was forget to run the server:
    php -S 127.0.0.1:8000 -t public
    it's been work perfectly, your tutorial is really awesome

  • 2018-03-15 Kavitha

    @weaverryan Thx.

  • 2018-03-15 Amy

    Thank you. I'll confess that I had done the getting started bit from the symfony page, and then used my up arrow and simply changed the project name to start the_spacebar. I didn't notice the difference in the commands. I apologize for doubting you.

  • 2018-03-14 weaverryan

    Hi Kavitha!

    Good job finding that GitHub pull request! So, here is some information about what's happening:

    1) Due to some recent changes in Symfony, it appears that *sometimes* the pretty welcome page doesn't display. The pull request you linked to will fix this. But, it has not been included in a release yet. At some point over the next few weeks, it will be included in a new Symfony release, and this issue should go away.

    2) BUT, it's ok! The pretty welcome page was just meant to be a friendly first thing to see. But if you see "No route found GET /" instead of the welcome page, that's ok - your app is working perfectly fine and you can continue like normal. You'll learn about routes over the next few chapters how you can define routes in order to build pages.

    If you have any other doubts or questions, let us know!

    Cheers!

  • 2018-03-14 Kavitha

    I am getting No route found GET / for my Symfony 4 Welcome page. Updated UrlMatcher.php, PhpMatcherDumperTest.php.
    Based on Gitlab Issue https://github.com/symfony/...
    Still I am having same error. Could anyone throw some light.

  • 2018-03-12 weaverryan

    Hi Amy!

    That *is* disheartening! You should be having success early on in the tutorial :).

    So let me explain, and help debug! First, I *did* just try the steps in the tutorial and I DO still get the welcome page. So, there's a bit of a mystery there. Make sure you're running this command exactly:


    composer create-project symfony/skeleton the_spacebar

    If you follow the "Getting Started" docs, it's actually a *slightly* different command - it uses symfony/website-skeleton. The difference is that symfony/website-skeleton comes with more features. And *indeed*, if you use it, you will see the "No route found" error instead of the pretty welcome page? Why? Well, the pretty welcome page is shown when your have a new site with *zero* routes. When you use symfony/skeleton, this gives us a "tiny" Symfony project with zero routes (hence why you should see the welcome page). When you use the symfony/website-skeleton, it's basically the "symfony/skeleton" + more features... including some debugging routes (you can see them by running php bin/console debug:router at the command line). Thanks to these routes, Symfony does *not* show the welcome page anymore. It's a bit of an unfortunate, confusing thing. That welcome page is meant to be friendly and helpful, but it disappears as *soon* as the first route is added to the system (whether you added that route or whether it was added by some vendor package).

    I hope this helps explain! I'm still not sure why you don't see the welcome page by following this tutorial, but it's actually not a problem and you can continue on :).

    Cheers!

  • 2018-03-12 Victor Bocharsky

    Hey Tess,

    Well, I'm sure it's not related to the git operations you did. Are you in the prod or dev environment? Because, in dev environment you should see a big Symfony error if something went wrong. If you don't see this Symfony error - you probably can't reach the website at all. Can you try to restart your built-in PHP web server? To stop it, press "Ctrl + C" and then run it again with "bin/console server:run". Does it fix the problem? If you still have this error, try to watch logs when hitting website: execute "tail -f var/log/dev.log" (or prod.log if you're in prod env) and reload the page. Do you see any new logs in the output?

    Cheers!

  • 2018-03-12 Tess Hsu

    HI victor,
    this is amazing, somehow in the final I had problem too, as type $ git add .
    $ git commit
    in terminal, i try to add the first commit message
    then nothing happend instead the url: http://127.0.0.1:8000/
    show the site is not reachable, before git commit it was worked

    could you help me in this point?
    cheers

  • 2018-03-10 Amy

    I'm hitting what seems to be a known issue - out of the box, I'm getting No route found for "GET /" rather than the welcome page. It's disheartening that following both your tutorial and the basic instructions on the getting started page hit this issue.

  • 2018-03-05 Victor Bocharsky

    Hey iTor,

    It's kind of expected, it depends on your PHP version. Symfony 4 required PHP 7.1.3, so if you're on a different PHP version which is less than 7.1.3, you won't be able to install Symfony 4 until upgrade your PHP version. You can check your PHP version with:

    php --version

    Cheers!

  • 2018-03-05 iTor

    Hello! Thanks for this new tutorial on Symfony! I have learnt quite a lot from some other courses on this page.

    I have a problem (maybe not exactly a problem) with this one however. I am following the tutorial in Windows, and whenever I run php composer.phar create-project symfony/skeleton the_spacebar it creates a project for symfony3 instead of 4 (3.4.5 versions to be exact) Is this normal?

    Thanks, I'll be following with interest!

  • 2018-02-06 Victor Bocharsky

    Yo Robertino!

    Good news hearing they switched to Symfony 3.4 - that's a big step into direction of Symfony 4. Actually, Symfony 3.4 + Flex = Symfony 4. Symfony 4 just does not have all those BC layers from Symfony 3.x. So yes, if you're on 3.4, using Flex, and already fixed all the deprecations - you're ready to migrate to Symfony 4. Well, the big difference probably in the file structure, you know.

    Yes, we're working hard on releasing new tutorials based on Symfony 4, so will have the same Doctrine-related, Form-related tutorials as earlier for Symfony 3 but in a bit different way - this time based on our brand new "Stellar" project.

    Yes, all the Symfony 4 related projects will be added to Symfony 4 track. Also, if you're subscribed to our newletter on your Profile page: https://knpuniversity.com/p... - you'll receive a monthly emails with information about new courses. Also, you can look closer after Course Updates page: https://knpuniversity.com/p... - to see new updates. Or, check out our upcoming screencasts from time to time here: https://knpuniversity.com/c...

    Probably so, but it depends. The problem is that we start new tutorial based on the previous, for example, we'll start Forms only after Doctrine which makes sense, that's why we're not able to released both tutorials at the same time, since we need to completely finish the first one to start working on the 2nd. But we're doing our best to released more Symfony 4 tutorials faster.

    Cheers!

  • 2018-02-06 Robertino Vasilescu

    Heya guys,
    This track reiterates the Symfony3 updated for S4 but I am following it with great interest.
    O couple of questions if you still don't mind :-)
    I came to Symfony because I develop for Prestashop and they recently switched to Symfony 3.4.
    First question: as far as I understand S3.4 is very similar to S4+ but still, any major differences I should have in mind?
    Second question: what about the other (many) tutorials you have for S2 -S3.4, do you plan to update them for S4 too?
    In such a case will they be added to the S4 track or will we be notified of the updates?
    Will this update take long?
    Please stop eating and sleeping, ask Tesla for some batteries and keep it going :-)

  • 2018-01-31 Diego Aguiar

    I've never used RUID before, so, I don't know either what could interfere, but if you find it out, let us know!

    Have a nice day :)

  • 2018-01-31 JLChafardet

    Thank you! yeah I somehow remember that I was playing with RUID2 module some ago, but never thought it would actually cause issues with symfony/laravel.... gota investigate that a bit more for future reference!

  • 2018-01-31 Diego Aguiar

    Hey JLChafardet

    Welcome back! We are happy to see you again and that you could fix your problem :)

    Cheers!

  • 2018-01-31 JLChafardet

    solved it, was ruid module of apache phuking with me. sorry :D

  • 2018-01-31 JLChafardet

    Heya weaverryan how's going? I'ts been a while!

    I'm receiving an odd message, untrusted host from symfony this is the first time it happens to me! I've been away from code for quite a while due to unexpected issues and now that I'm coming back I'm having this headache, google seems to not know much tho :S any ideas?