Creating a new Symfony 5 Project

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 friends! And welcome to the world of Symfony 5... which just happens to be my favorite world! Ok, maybe Disney World is my favorite world... but programming in Symfony 5 is a close second.

Symfony 5 is lean and mean: it's lightning fast, starts tiny, but grows with you as your app gets bigger. And that's not marketing jargon! Your Symfony app will literally grow as you need more features. But more on that later.

Symfony 5 is also the product of years of work on developer experience. Basically, the people behind Symfony want you to love using it but without sacrificing quality. Yep, you get to write code that you're proud of, love the process, and build things quickly.

Symfony is also the fastest major PHP framework, which is no surprise: - its creator also created the PHP profiling system Blackfire. So... performance is always a focus.

Downloading the Symfony Installer

So... let's do this! Start off by going to http://symfony.com and clicking "Download". What we're about to download is not actually Symfony. It's an executable tool that will help make local development with Symfony... well.. awesome.

Because I'm on a Mac, I'll copy this command and then go open a terminal - I already have one waiting. It doesn't matter where on your filesystem you run this. Paste!

curl -sS https://get.symfony.com/cli/installer | bash

This downloads a single executable file and, for me, puts it into my home directory. To make it so that I can run this executable from anywhere on my system, I'll follow the command's advice and move the file somewhere else:

mv /Users/weaverryan/.symfony/bin/symfony /usr/local/bin/symfony

Ok, try it!

symfony

It's alive! Say hello to the Symfony CLI: a command-line tool that will help us with various things along our path to programming glory.

Starting a new Symfony App

Its first job will be to help us create a new Symfony 5 project. Run:

symfony new cauldron_overflow

Where cauldron_overflow will be the directory that the new app will live in. This also happens to be the name of the site we're building... but more on that later.

Behind the scenes, this command isn't doing anything special: it clones a Git repository called symfony/skeleton and then uses Composer to install that project's dependencies. We'll talk more about that repository and Composer a bit later.

When it's done, move into the new directory:

cd cauldron_overflow

And then open this directory in your favorite editor. I already have it open in my favorite: PhpStorm, which I did by going to File -> Open Directory and selecting the new project folder. Anyways, say hello to your brand new, shiny, full-of-potential new Symfony 5 project.

Our App is Small!

Before we start hacking away at things, let's create a new git repository and commit. But wait... run:

git status

On branch master, nothing to commit.

Surprise! The symfony new command already initialized a git repository for us and made the first commit. You can see it by running:

git log

Add initial set of files

Nice! Though, I personally would have liked a slightly more epic first commit message... but that's fine.

I'll hit "q" to exit this mode.

I mentioned earlier that Symfony starts small. To prove it, we can see a list of all the files that were committed by running:

git show --name-only

Yea... that's it! Our project - which is fully set up and ready to leverage Symfony - is less than 15 files... if you don't count things like .gitignore. Lean and mean.

Checking Requirements

Let's hook up a web server to our app and see it in action! First, make sure your computer has everything Symfony needs by running:

symfony check:req

For check requirements. We're good - but if you have any issues and need help fixing them, let us know in the comments.

Starting the PHP Web Server

To actually get the project running, look back in PhpStorm. We're going to talk more about each directory soon. But the first thing you need to know is that the public/ directory is the "document root". This means that you need to point your web server - like Apache or Nginx - at this directory. Symfony has docs on how to do that.

But! To keep life simple, instead of setting up a real server on our local machine, we can use PHP's built-in web server. At the root of your project, run:

php -S 127.0.0.1:8000 -t public/

As soon as we do that, we can spin back over to our browser and go to http://localhost:8000 to find... Welcome to Symfony 5! Ooh, fancy!

Next: as easy as it was to run that PHP web server, I'm going to show you an even better option for local development. Then we'll get to know the significance of the directories in our new app and make sure that we have a few plugins installed in PhpStorm... which... make working with Symfony an absolute pleasure.

Leave a comment!

  • 2020-06-28 weaverryan

    Hey Nicky Speight!

    You "shouldn't" (I'm using quotes because... in programming, there are always surprises 😉) need to change any permissions to get things working on this step. But if this comes up again and you're having file permissions issues (and care enough to debug), let us know what's going on and we'll see if we can help :).

    Cheers!

  • 2020-06-24 Nicky Speight

    File and folder move command issues on Linux (File permissions Step 2)

    sudo chmod -R a+rwx /path/to/folder

    https://smallbusiness.chron....

    Bear in mind I am not a Linux security expert so I don't know if the site is going OTT with folder permissions. But I had move permission denied errors and the above worked and stopped the error.

    I assume this is fixed now but for all future viewers.

  • 2020-06-08 Vladimir Sadicov

    Hey Abdelali Kabou

    What's the question? ) It shows that you should configure your php to match all requirements.

    Cheers!

  • 2020-06-07 Abdelali Kabou

    when i run symfony check:req i get this log messge

    * intl extension should be available
    > Install and enable the intl extension (used for validators).

    * a PHP accelerator should be installed
    > Install and/or enable a PHP accelerator (highly recommended).

    * short_open_tag should be disabled in php.ini
    > Set short_open_tag to off in php.ini*.

  • 2020-05-31 weaverryan

    Hey @wuwu!

    Hmm, sorry about that! Ok, a few things:

    > If I try to download it i get the error during installation:
    > Status: failed to send request to the HTTP server.

    Do you see this error in your browser when you click "Download setup.exe"? Or do you see this error while running setup.exe?

    > I can only install with console: create-project etc...

    This is actually ok. When we run symfony new cauldron_overflow, this is equivalent to the command you see it output:


    composer create-project symfony/skeleton cauldron_overflow

    The one OTHER thing that the symfony new command does is initialize a new git repository and make an initial commit. The equivalent commands would be:


    git init
    git add .
    git commit -m "Initial commit"

    I hope this helps :). Btw, the Symfony CLI also has an issue queue - https://github.com/symfony/...

    Cheers!

  • 2020-05-29 wuwu

    I can't install symfony CLI.
    If I try to download it i get the error during installation:
    Status: failed to send request to the HTTP server.
    If i press "If you prefer, you can download the binaries directly from GitHub: 32-bit or 64-bit platforms." button and run it it just opens up, run smth i can't see because its two fast and closes itself.

    I can only install with console: create-project etc...
    I'm on win7.

  • 2020-05-06 Diego Aguiar

    That kind of problems are hard to spot at first sight but after you go through it, the next time you will fix it right away. Cheers!

  • 2020-05-06 Antonina NGUYEN

    Thank you, Diego,
    Finally, I found the solution by my-self :))
    In case if somebody has the same problem, I explain.

    Yes, the system PHP version was correct, well registered in the PATH etc.
    But! As I have WAMP installed in my computer, Symfony takes the version from WAMP. You can say - Just change the version of PHP in WAMP. Yes, good idea, but there are two options where and for which part you change PHP version.
    The first one which everybody knows and use.
    Be sure that your WAMP is running. Left button click on WAMP icon -> PHP -> Version and choose the version that you want.
    This is not the solution to change PHP version using by Symfony
    The second one is important (but unfortunately I didn't find any words in Internet about if even if I was searching in three languages). So, Right button on WAMP icon -> Tools -> Change PHP CLI version.
    And that's it!!! If somebody explains this simple way to fix the Symfony PHP version.. It would avoid losing 2 days for nothing, instead of learning the more important things..

    But thank you any way for your sympathy. :)

  • 2020-05-05 Diego Aguiar

    Hey Antonina NGUYEN

    Symfony5 requires you to run on PHP7.2+ That's why you can't install it. Try upgrading your PHP version or using a lower Symfony version. I think Symfony3.4 allows PHP5.6

    Cheers!

  • 2020-05-05 Antonina NGUYEN

    Hi,
    I created a project by composer create-project symfony/skeleton mySymfony
    But.. after I can do nothing because after installing Symfony to use some kind of "symfony console" I have the message
    Fatal Error: composer.lock was created for PHP version 7.2 or higher but the current PHP version is 5.6.40.
    exit status 1

    I installed well the version 7.2.30 of php, but Symfony don't want to see it.

    I checked and well identified where is php (in the PATH)

    What I can do??

    I work in Windows

    When I delete everything and try to reinstall and check requirements it's again version 5.6.40
    c:\wamp64\www>symfony check:requirements

    Symfony Requirements Checker
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    > PHP is using the following php.ini file:
    C:\wamp64\bin\php\php5.6.40\php.ini
    > Checking Symfony requirements:
    ........................W..........
    [OK]
    Your system is ready to run Symfony projects
    Optional recommendations to improve your setup
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    * a PHP accelerator should be installed
    > Install and/or enable a PHP accelerator (highly recommended).

  • 2020-04-28 Max

    Diego Aguiar - thanks for confirming. Updating to PHP7.3 and updating the $PATH worked well. I'm now at the latest Symfony in the default project 5.0.8. Much appreciated!

  • 2020-04-28 Diego Aguiar

    Hey @Max

    That's due to your PHP version, if I remember correctly, Symfony5 works with PHP7.2+

    Cheers!

  • 2020-04-28 Max

    I am using the following command to create a skeleton project: symfony new cauldron_overflow

    However, when I start the server and open the localhost in the web browser - the homepage is showing "Symfony 4.4.8" - I have confirmed this is the version in the symfony.lock file as well.

    I've also tried to add the --version=5.0.9 at the end of the project creation command but that doesn't work.

    I'm on php 7.1 on Mac.

    Thanks.

  • 2020-04-14 Victor Bocharsky

    Hey Rodrigo,

    Yes, those recommendations are optional, so you still can use the project. To install them - you would need to do it for your installed PHP. Google how to do it for your system, it may require some missing PHP extensions or special configuration in your php.ini file. But if you're using this project for testing purposes only just to follow the course - you can completely ignore them.

    Cheers!

  • 2020-04-14 Rodrigo Valentim

    Hi, checking the requirements I have that info:

    Optional recommendations to improve your setup
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    * mb_strlen() should be available
    > Install and enable the mbstring extension.

    * posix_isatty() should be available
    > Install and enable the php_posix extension (used to colorize the
    > CLI output).

    * intl extension should be available
    > Install and enable the intl extension (used for validators).

    That's even after I tried to install manually, e.g. composer require symfony/polyfill-mbstring
    Is it possible to continue without recommendations? And how to install it?

  • 2020-04-06 Diego Aguiar

    Oh sorry, I meant the last step, moving the binary file to /usr/local/bin/. If you already downloaded the binary but the bash script failed due to permissions, then you just have to make sure that /Users/stephenspittal/.symfony/bin/symfony exists and the move it to its destination manually

  • 2020-04-06 Stephen Spittal

    Sudo symfony?

  • 2020-04-06 Diego Aguiar

    ahh it makes sense now! Try running it with sudo

  • 2020-04-06 Stephen Spittal

    Diego it tells me I don't have permissions

  • 2020-04-06 Diego Aguiar

    Interesting... can you double-check that the directories /Users/stephenspittal/.symfony and /usr/local/bin/ exists in your computer?
    It's possible that you need to re-open your terminal after moving the binary

    Cheers!

  • 2020-04-03 Stephen Spittal

    It downloads and installs as far as I can tell and tells me to move to use it globally

  • 2020-04-03 Diego Aguiar

    Hey Stephen Spittal

    It's likely that you download the file in a different folder. What happens when you run curl -sS https://get.symfony.com/cli/installer | bash?

  • 2020-04-03 Stephen Spittal

    Hello i have tried to follow along with this however i get an error at the point of moving smfony mv: rename /Users/stephenspittal/.symfony/bin/symfony to /usr/local/bin/symfony: No such file or directory

  • 2020-03-24 Vladimir Sadicov

    hm, looks like symfony is latest, so about -vvv flag, I mean do symfony new cauldron_overflow -vvv and try to figure out which step is failing

  • 2020-03-24 Curtis Wayne

    Hi!
    I've got this version :
    Symfony CLI version v4.13.3 (c) 2017-2020 Symfony SAS

    and this with symfony -vvv :
    24/03 08:18:37 DEBUG symfony Looking for a potential unlinked project root based on the CWD

    What can i do with it?

    Have a nice day.

  • 2020-03-23 Vladimir Sadicov

    Hey Curtis Wayne

    Do you have latest Symfony CLI version? You can check it with symfony -v. Also try to use -vvv verbosity flag with command to find out what exactly can be wrong.

    Cheers!

  • 2020-03-21 Curtis Wayne

    Hello,
    I'm on kubuntu and I installed symfony 5 but I've got a problem when i try to create the new cauldron project. The waiting spin turns endlessly and nothing else happens. :/

  • 2020-03-18 Diego Aguiar

    Hey Pleaseenteryourname

    Have you read this part of the documentation? https://symfony.com/doc/cur...

    Cheers!

  • 2020-03-17 Pleaseenteryourname

    When checking the recommendations Symfony says to install a PHP accelerator. I can't find it anywhere, all documentation is for Linux/Ubuntu. I've also read some comments about an accelerator not being necessary for PHP 5.3 and after because it is integrated in PHP itself. Any recommendations?