Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Hello Symfony

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.

Welcome. Hello. Hi, my name is Ryan and I have the absolute pleasure to introduce you to the beautiful and fascinating and productive world of Symfony 6. Seriously, I feel like Willie Wonka inviting you into my chocolate factory, except with hopefully less sugar-related injuries. Anyways, if you're new to Symfony, I'm... honestly a bit jealous! You're going to love the journey... and hopefully become an even better developer along the way: you're definitely going to build some cool stuff.

The secret sauce of Symfony is that it starts tiny, which makes it easy to learn. But then, it scales up its features automatically through a unique recipe system. In Symfony 6, those features include new JavaScript tools and a new security system... just to name two of the many new things.

Symfony is also lightning fast with a huge focus on creating a joyful developer experience, but without sacrificing programming best practices. Yea: you get to love coding and love your code. I know... that sounded cheesy, but it's true.

So come with me and you'll be in a world of pure elucidation.

That's my first time singing in these tutorials... and maybe my last. Let's get started.

Installing the "symfony" Binary

Head over to https://symfony.com/download. On this page, you'll find some instructions - which will differ based on your operating system - on how to download something called the Symfony binary.

This is... not actually Symfony. It's just a command line tool that will help us start new Symfony projects and give us some nice local development tools. It's optional, but I highly recommend it!

Once you've installed this - I already have - open up your favorite terminal app. I'm using iTerm for mac, but it doesn't matter. If you got everything set up correctly, you should be able to run:

symfony

Or even better:

symfony list

to see a list of all the "things" that this symfony binary can do. There's a lot of stuff here: things that help with "local" development... and also some optional services for deployment. We'll walk through the stuff you need to know along the way.

Let's Start a Symfony App!

Ok, so we want to start a brand new shiny Symfony app. To do that run:

symfony new mixed_vinyl

Where "mixed_vinyl" is the directory the new app will be downloaded into. That's our top-secret project to combine the best part of the 90's - no, not dial-up internet, I'm talking about mix tapes - with the auditory delight of records. More on that later.

Behind the scenes, this command uses composer - that's PHP's package manager - to create the new project. More on that later.

The end-result is that we can move into our new mixed_vinyl directory. Open this folder up in your favorite editor. I'm using PhpStorm and I highly recommend it.

Meeting our new Project

So what did that symfony new command do? It bootstrapped a new Symfony project! Ooh. And we already have a git repository. Run:

git status

Yep: on branch main, nothing to commit. Try:

git log

Cool. After downloading the new project, the command committed all of the original files automatically... which was very nice of it. Though I do wish that first commit message was a bit more rock n' roll.

What I really want to show you is that our new project is super small! Try this command:

git show --name-only

Yup! Our entire project is... about 17 files. And we'll learn about all of these along the way. But I want you to feel comfortable: there's not a lot of code here.

We're going to add features little-by-little. But if you did want to start with a bigger, more fully-featured project, you can do that by running that symfony new command with --webapp.

Tip

If you want a fully-dockerized new Symfony app, check out https://github.com/dunglas/symfony-docker

Checking System Requirements

Before we jump into coding, let's make sure our system is ready. Run another command from the symfony binary:

symfony check:req

Looks good! If your PHP install is missing any extensions... or there are any other problems... like your computer is actually a teapot, this will let you know.

Starting the Dev Web Server

So: we have a new Symfony app over here... and our system is ready! All we need now is a subwoofer. I mean web server! You can set up a real web server like Nginx or something trendy like Caddy. But for local development, the Symfony binary can help us. Run:

symfony serve -d

And... we have a web server running! Come back!

The first time you run this, it might ask you to run a different command to set up an SSL certificate, which is nice because then the server supports https.

Moment of truth! Copy the URL, spin over to your browser, hold your breath and woo! Hello Symfony 6 welcome page... complete with fancy color changes whenever we reload.

Next: let's meet - and become friends with - the code inside our app, so we can demystify what each part does. Then we'll code.

Leave a comment!

32
Login or Register to join the conversation
Vincent S. Avatar
Vincent S. Avatar Vincent S. | posted 1 year ago

Thank you for this tutorial and all the content !

Merci beaucoup pour ce travail et toutes ces informations !

Vincent

3 Reply

Vincent S. you're welcome!

Reply
Kevin-M Avatar

Is there any way to get symfony serve to listen on an address other than localhost? I have symfony set up in a VM, and would like to connect from Firefox running on a physical PC. If not, an ssh tunnel works as a work-around.

Reply

Hey Kevin,

I'm not sure it's possible, probably you need to set up a real web server for this, Symfony binary usually is used for local development. Though, I think you need to think about somehow to open that port to your VM so you could run the Sf binary there but connect to it from your local machine (outside of VM). I think it should be possible, maybe try to google some info on the internet.

Cheers!

Reply
Robert J. Avatar
Robert J. Avatar Robert J. | posted 1 year ago

Hi, I want to install the Symfony CLI on Windows 10 but would like to avoid installing Scoop and use the downloadable binaries instead. However if I execute the symfony.exe file I get the alert that I need to download an app for this task and whether I would like to search for that app in the App Store. After confirming that nothing happens.
What am I doing wrong or how do I go about installing Symfony without Scoop?

Reply

Hey Robert J.

My first suggestion is to user Windows WSL 2. It's an embedded Linux environment which works pretty well (that's what I use actually)

If you don't want to change to WSL, I found this SO answer which may help you out: https://stackoverflow.com/a...

I hope it helps. Cheers!

Reply
Robert J. Avatar
Robert J. Avatar Robert J. | MolloKhan | posted 1 year ago | edited

Thanks MolloKhan, yes WSL is also a good solution. I tried it and it works well. What I wanted to achieve though was to install the Symfony CLI natively on Windows but without installing Scoop first. The stackoverflow-link you posted however suggests using Scoop for the installation. But with WSL it works fine and I'm OK with that. Thanks again.

Reply
Jesus M. Avatar
Jesus M. Avatar Jesus M. | posted 1 year ago

how fix the url character encoding? in the browser the url appears "https:\/\/symfonycast.s3.amazonaws.com\/sample.mp3"

Reply
Cesar Avatar

Hello guys.
I have always started a Symfony project, since version 3, as you describe in your tutorial. However, this time I would like to do a full-dockerize SF app but I don't have clear the steps to do that. I was reading https://symfony.com/doc/cur... but it's not very clear for me how to start the project. Please, can you explain me the steps in a general level of what to do? Specially because now Symfony creates some docker files and put this https://github.com/dunglas/... in the tip.
I hope you can help me.
Cesar

Reply

Hey Cesar!

Sorry for VERY slow reply - we're usually much faster, but i'm prepping for conference week next week!

To get the full Docker setup, I believe what you need to do is:


git clone git@github.com:dunglas/symfony-docker.git my_new_project
cd my_new_project
rm -rf .git

Then run the commands you see here: https://github.com/dunglas/symfony-docker#getting-started - this will actually create a brand new Symfony project for you run inside that directory, but everything is running entirely from Docker.

So, the basic idea is:

A) To go "full docker" use https://github.com/dunglas/symfony-docker
B) Regardless of whether you go "full docker" or only "part Docker", as you install new packages, if that package contains Docker config, it will be added to your project. This config works with both the full or part Docker setup.

Let me know if this helped :).

Cheers!

Reply
Cesar Avatar

Thank you Ryan for answering.
I have followed your instructions and I could star the new project 100% with docker. But, at the end, I have two issues:
1. I am not able to use Composer inside the new project (an error appeared but I don't have problems with Composer in my computer for other projects).
2. I lost the dev tool bar in localhost (and I can not use the symfony server inside the new project)
Probably I am doing something wrong. Is there any way you can add a video showing this process?
Cheers!

Reply

Yo Cesar!

  1. I am not able to use Composer inside the new project (an error appeared but I don't have problems with Composer in my computer for other projects).

Interesting. Are you running composer from your local machine or inside of the container? In the full Docker setup, everything is meant to be run from inside of a container. So, it would be docker-compose exec php composer install

But let me know. Also, if you are running it inside the container, what is the error?

  1. I lost the dev tool bar in localhost (and I can not use the symfony server inside the new project)

That's true that you can't use the symfony server inside the new project. Or, better-said: there is no reason to use it, because the full-docker setup includes a container that has a web server. So, a web server is already running.

About the dev toolbar, I'm not sure why this wouldn't show up. If you can load the site, the toolbar loads via an Ajax request back to the same server. Do you get an error? Or does it just not show up? Is it possible it's just because the debug bar isn't installed into your app yet? I was able to get it to load after installing it with docker-compose exec php composer require debug.

Is there any way you can add a video showing this process?

This is a nice idea - but we won't have time too soon for it :).

Cheers!

Reply

Hi, Thanks for a new Symfony course. I've been following since Sf4. However, this time I got a new machine and have this problem right from the start...
I installed the symfony-cli (Ubuntu) but it cannot find the binary.

When I try to use the symfony command it says it cannot find it <b>-bash: /usr/local/bin/symfony: No such file or directory</b>

I've also tried apt remove with the --purge option and then reinstalling the cli

If you have any hints, thanks in advance.

Here is a log of my terminal:
`$ sudo apt install symfony-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
symfony-cli
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 5866 kB of archives.
After this operation, 14.5 MB of additional disk space will be used.
Get:1 https://repo.symfony.com/apt symfony-cli 5.4.8 [5866 kB]
Fetched 5866 kB in 2s (2761 kB/s)
Selecting previously unselected package symfony-cli.
(Reading database ... 62284 files and directories currently installed.)
Preparing to unpack .../symfony-cli_5.4.8_amd64.deb ...
Unpacking symfony-cli (5.4.8) ...
Setting up symfony-cli (5.4.8) ...
$ <b>symfony list
-bash: /usr/local/bin/symfony: No such file or directory</b>
$ php -v
PHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies

with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

$ composer -V
Composer version 2.3.5 2022-04-13 16:43:00`

Reply

Solved it. If anyone finds the same issue, this is what I had to do.

  1. Move the /usr/bin/ directory in the /etc/environment file BEFORE the /usr/local/bin/ and logout and login to terminal again.
  2. After this, the symfony command works, but I got some PHP deprecations and dependency errors when running symfony new project_name.
  3. Downgraded to composer 1 (I was using composer 2) with composer self-update --1 but still had some dependency error: symfony/flex[v2.0.0, ..., v2.1.8] require composer-plugin-api ^2.1
  4. Downgraded to use PHP 7.4 instead of 8.1 (8.0 didn't work either) with sudo update-alternatives --config php

After this all went fine.

Reply
Richard Avatar
Richard Avatar Richard | posted 1 year ago

Hi, thanks for your cheerful attitude and the content of your tutorials.
I've got a problem: I can't understand while I strictly followed your coding, I still get Symfony 5.4.* on screen.
And when I run : symfony new my_project --version="6.0", I can see an error that has something to interfer with the php context.
So I force upgrade via brew to PHP 8.0* and I still get the same trouble.

Reply

Hey Richard, thanks for your kind words :)

Did you download the code from this page? it should get you Symfony 6
What PHP version are you running on? execute php -v. I'm asking because Symfony 6 requires PHP ^8.0.2 to work, so, if you are on a lower PHP version, the Symfony CLI will detect it and give you an older Symfony version

Cheers!

1 Reply
Richard Avatar
Did you download the code from this page?


Sorry, I do not know where I could download the code from this page.

With MAM pro I set the php version to 8.0.8 for the folder where I want to create the project.
But if I use the terminal in the folder it say php -v 7.4.29.
I'm sure that it'is the node of the problem. But I don't know how to set php to 8.0.8 or later, for all users.
I've forced an upgrade to php 8 with brew but I can't get out of the issue.
Thanks for attention, maybe you'll find a way.
Anyway, it's not so bad to get stuck to Symfony 5.

1 Reply
Francisco C. Avatar
Francisco C. Avatar Francisco C. | posted 1 year ago

HI,
I put the command "symfony new myproject" but when I run my local web with symfony serve -d ... the main page is under Symfony 5.4.7 ... Why?

Reply

Hey Francisco C.

That's odd. I just gave it a try and it installed Symfony 6 on my machine. Try upgrading your Symfony CLI

Cheers!

Reply
Francisco C. Avatar
Francisco C. Avatar Francisco C. | MolloKhan | posted 1 year ago

Hey I have Symfony CLI version v4.28.1 (c) 2017-2022 Symfony SAS ... but the problem continous

Reply

That may be the problem. I'm on Symfony CLI 5.4.5 and it works as expected - Try upgrading it and give it another try. If that doesn't work, perhaps reinstalling the CLI will do the trick

Reply
Francisco C. Avatar
Francisco C. Avatar Francisco C. | MolloKhan | posted 1 year ago

I discover it ... the php version ... I was under 7.4.28 ... I changed to 8.2 and it works

Reply

Of course! How I didn't think about that. Good job man!

1 Reply
Ruslan I. Avatar
Ruslan I. Avatar Ruslan I. | posted 1 year ago

I'm new to Symfony. Do you think it would be better to watch Symfony 5 tutorials? Is there a big difference between 5 and 6 versions?

Reply

Hey H3ck,

Welcome to SymfonyCasts! If you're going to start from scratch - I'd recommend you to follow the new Symfony 6 track unless you already have a project that is based in the previous Symfony 5 version and you have to maintain it - it would be better to follow the version you have then.

The only problem is that Symfony 6 is very fresh and so we don't have too much screencasts about it, though we're actively working on recording new Symfony 6 related courses lately, so more screencasts will come soon! So, it depends on your learning speed, so if you would watch everything we have for Symfony 6 - I'd recommend you to switch to Symfony 5 then - nothing much was changed in Symfony 6 since Symfony 5, so you should follow our Symfony 5 tutorials using Symfony 6 without many issues. But if you got stuck somewhere - feel free to ask questions in the comments below the video mentioning your Symfony version and we will definitely try to help you so you could continue following the course!

So, in short, if you're going to start a new project - I'd recommend you to start it with Symfony 6 nowadays.

Cheers!

1 Reply
Ruslan I. Avatar
Ruslan I. Avatar Ruslan I. | Victor | posted 1 year ago

Thank you very much!

Reply

Hey H3ck,

You're welcome! If you ever have any problems following SymfonyCasts tutorials - feel free to let us know in the comments below the video, we will help!

Cheers!

Reply
Ruslan I. Avatar
Ruslan I. Avatar Ruslan I. | Victor | posted 1 year ago

Well, I faced a problem. When I tried to pay for a Symfony 5 tutorial it said "Your card was declined". I suppose it has something to do with Russia-Ukraine war (I'm from Russia). But I'm really not supporting it. It's not fair. I'm just a regular guy who wants to program and improve my skills. I even can't link my card to PayPal. Can you please help me somehow, Виктор?

Reply

Hey H3ck,

We're sorry to hear that you're experiencing issues with purchasing our products. Please, let us know your email address registered on SymfonyCasts via our contact form: https://symfonycasts.com/co... - we will take a closer look at the reason why the payment card might be declined.

Cheers!

1 Reply
Dave V. Avatar
Dave V. Avatar Dave V. | posted 1 year ago

So excited for this to be done already :P

After going through the last course, and bits and pieces of many others on the site, I need to know, if I break away my business logic into their own classes, should I be passing the services and repos etc to them or should I be extending AbstractController for everything to have access to it all ?

Reply

Hey David,

We will definitely talk about this further in the upcoming chapters. You don't have to extend that AbstractController, but it has some good shortcuts that you can leverage, just take a look at that class to see them. So, it's up to you to use it or no. What about splitting your business logic into separate services to move it out of the controller - that's a great idea, and it will help you with testing that code, so it definitely worth it. About how to get access to them in the controller? Good question! The best practice would be to inject them into methods (see method injection). In case you have some services that you're using in *every* method of the controller - you can use "constructor injection" instead to unload the signature of your actions. In case you have a lot of services that you have to inject into the controller - take a look at "service subscriber" that will help you to declare the services you should have access to in the controller.

I hope this helps for now! But stay tune, all this will be covered later in this course ;)

Cheers!

2 Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=8.0.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "symfony/asset": "6.0.*", // v6.0.3
        "symfony/console": "6.0.*", // v6.0.3
        "symfony/dotenv": "6.0.*", // v6.0.3
        "symfony/flex": "^2", // v2.1.5
        "symfony/framework-bundle": "6.0.*", // v6.0.4
        "symfony/monolog-bundle": "^3.0", // v3.7.1
        "symfony/runtime": "6.0.*", // v6.0.3
        "symfony/twig-bundle": "6.0.*", // v6.0.3
        "symfony/ux-turbo": "^2.0", // v2.0.1
        "symfony/webpack-encore-bundle": "^1.13", // v1.13.2
        "symfony/yaml": "6.0.*", // v6.0.3
        "twig/extra-bundle": "^2.12|^3.0", // v3.3.8
        "twig/twig": "^2.12|^3.0" // v3.3.8
    },
    "require-dev": {
        "symfony/debug-bundle": "6.0.*", // v6.0.3
        "symfony/stopwatch": "6.0.*", // v6.0.3
        "symfony/web-profiler-bundle": "6.0.*" // v6.0.3
    }
}
userVoice