Chapters
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
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.
64 Comments
Vincent S. you're welcome!
If you're doing this in Windows & you run from WSL:
View your page at http(s)://localhost:8001 not http(s)://127.0.0.1:8001
This is because whether you create your project in WSL or not WSL, localhost will map correctly. The IP address from WSL will actually be something like 172.x.x.x not 127.x.x.x (try ip addr show in WSL)
The browser does not run from WSL, it runs from the Windows shell, and in that there is nothing running on 127.0.0.1
HTH
Yes, you're right. Windows WSL forces you to use localhost
instead of 127.0.0.1
.
Thanks for sharing it! Cheers!
At my doctrine.yaml I have the following configuration:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
I want to connect to 2 different databases with the following configuration:
dbal:
connections:
default_connection: default
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
This will give me the following error:
Invalid type for path "doctrine.dbal.connections.default_connection". Expected "array", but got "string"
When I delete the default_connection: default I get the following error:
>Unrecognized option "profiling_collect_backtrace" under "doctrine.dbal". Available options are "connections", "default_connection", "driver_schemes", "types".
How do I config this so I can connect to 2 databeses?
Hey Tim,
You almost nailed it, but mess up your configuration slightly. Try this one:
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
So as you see you have the wrong level for default_connection
.
Cheers!
Victor,
Is there a way I can reverse engineer the old_wtb database to entities? I found an article thats says to use the composer require symfony/orm-maker but it isn't supported anymore.
Hey Tim,
I think it should be in the core now, take a look at doctrine:mapping:import
command, it imports mapping information from an existing database. I suppose that's what you need.
Cheers!
I did try that with the following command: ./bin/console doctrine:mapping:import --em=old_wtb --path=src/Entity/OldWtb yaml
Now I get this error:
[critical] Error thrown while running command "doctrine:mapping:import --em=old_wtb --path='src/Entity/OldWtb' yaml". Message: "Property "jobofferalertuserqueue" in "ClassificationTag" was already declared, but it must be declared only once"
Meanwhile I also tried to connect to a third database. When I try the import command: ./bin/console doctrine:mapping:import --em=wp --path=src/Entity/Wp yaml
The following error shows:
"Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it."
This is my current config:
`doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
wp:
url: '%env(resolve:DATABASE_URL_WP)%'
profiling_collect_backtrace: '%kernel.debug%'
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
old_wtb:
connection: old_wtb
mappings:
OldWtb:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/OldWtb'
prefix: 'App\Entity\OldWtb'
alias: OldWtb
wp:
connection: wp
mappings:
OldWtb:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/Wp'
prefix: 'App\Entity\Wp'
alias: Wp`
Hey Tim,
I bet you should run that command for a new entity to avoid conflicts... I would recommend you to create a completely new and empty entity file and import it there even if you have already imported some fields manually. Then later you will be able to merge the new autogenerated entity from that import with your existing entity. That's. the best strategy I think.
About the 2nd error - hm, not sure, probably try to check the version of the DB you're trying to connect, and make sure you set up the server version correctly in your Doctrine config file, or most probably in your DATABASE_URL value.
I hope that helps!
Cheers!
Hi Victor,
Thank you for your quick reply. How can I run the command for a new entity? "I bet you should run that command for a new entity " I thought this config should do that:dir: '%kernel.project_dir%/src/Entity/OldWtb'
prefix: 'App\Entity\OldWtb'
About the other error I did check the settings. I got these off my old project. But I will double check and try to debug.
Hey Tim,
you can do it with some workarounds I believe, e.g. you can just temporarily delete that ClassificationTag
in your project and run the command... Or if that command requires an entity - you can at least temporarily delete or comment out the problematic property there.
Cheers!
Hey Victor,
Thank you for your reply. Unfortuntaly the configuration above isn't working for me.
This is my full config at doctrine.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '16'
profiling_collect_backtrace: '%kernel.debug%'
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
And this is the error I get:
Unrecognized option "profiling_collect_backtrace" under "doctrine.dbal". Available options are "connections", "default_connection", "driver_schemes", "types".
Can you see what's wrong?
I think I found it. The profiling_collect_backtrace: '%kernel.debug%' should also be indented another level.
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
profiling_collect_backtrace: '%kernel.debug%'
It was like this in my previously config:
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
profiling_collect_backtrace: '%kernel.debug%'
Hey Tim,
Good catch! I'm glad you were able to find it yourself :)
Most problems with config are about the wrong indentation. You can always leverage bin/console config:dump doctrine
command to double-check that every option is on the correct level.
Cheers!
Hi Victor,
I ran into a new issue. At my project I manually created a new entity to connect to my old_wtb. My doctrine.yaml is as following:
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
old_wtb:
url: '%env(resolve:DATABASE_URL_OLD_WTB)%'
wp:
url: '%env(resolve:DATABASE_URL_WP)%'
profiling_collect_backtrace: '%kernel.debug%'
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
default_entity_manager: default
entity_managers:
default:
connection: default
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
old_wtb:
connection: old_wtb
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
OldWtb:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/OldWtb'
prefix: 'App\Entity\OldWtb'
alias: OldWtb
wp:
connection: wp
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
OldWtb:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/Wp'
prefix: 'App\Entity\Wp'
alias: Wp
Company Entity
namespace App\Entity\OldWtb;
use App\Repository\OldWtb\CompanyRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CompanyRepository::class)]
class Company
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $companyName = null;
public function getId(): ?int
{
return $this->id;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): static
{
$this->companyName = $companyName;
return $this;
}
}
Now at my controller I'm trying to dump the companies for the old_wtb and default Manager.
BaseController.php
namespace App\Controller;
use App\Entity\Company;
use App\Entity\OldWtb\Company as PreviousCompany;
class BaseController extends AbstractController
{ #[Route('/companies', name: 'get_company')]
public function getCompanies(Request $request, ManagerRegistry $managerRegistry)
{
$defaultEntityManager = $managerRegistry->getManager('default');
$currentCompanies = $defaultEntityManager->getRepository(Company::class)->findAll();
dump($currentCompanies);
$oldWtbEntityManager = $managerRegistry->getManager('old_wtb');
$oldCompanies = $oldWtbEntityManager->getRepository(PreviousCompany::class)->findAll();
dd($oldCompanies);
}
}
But I only see the default Manager Companies twice instead of the old_wtb companies and default companies.
If I dump the $defaultEntityManager and the $oldWtbEntityManager I can see that they are indeed different.
What's wrong?
Hey Tim,
Unfortunately, we don't have bandwidth to answer personal project related questions, and this topic is advanced and not covered by this tutorial.
My guess is that the default entity manager should be pointed to the subdirectory as well because right now it's literally linked to the global src/Entity/ folder which includes both your subdirectories: OldWtb and Wp. I would recommend you to use 3 separate folders like it's mentioned in the official docs, i.e. try to change the default entity manager prefix to src/Entity/Defaul/ for example. This way you will have 3 separate subfolders and will not have any overlapping.
I hope this helps and thank you for understanding!
Cheers!
Hi Victor,
I understand you don't have the bandwith to deep dive in all the questions. I thought the question could be of value for everyone that wants to have multiple database connections.
I did try to change the default entity manager prefix but then I had to change my entire code. But I found a solution!
At my project I did change the directory structure of the external Entities. So now I have my project entity folder like this: project/src/Entity
My Entity folder for the external Entities is Like this:
project/src/ExternalData/Entity/OldWtb
project/src/ExternalData/Repository/OldWtb
and
project/src/ExternalData/Entity/Wp
project/src/ExternalData/Repository/Wp
My config at project/config/packages/doctrine.yaml
is as following:
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
default_entity_manager: default
entity_managers:
default:
connection: default
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
old_wtb:
connection: old_wtb
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
OldWtb:
is_bundle: false
dir: '%kernel.project_dir%/src/ExternalData/Entity/OldWtb'
prefix: 'App\ExternalData\Entity\OldWtb'
alias: OldWtb
wp:
connection: wp
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
Wp:
is_bundle: false
dir: '%kernel.project_dir%/src/ExternalData/Entity/Wp'
prefix: 'App\ExternalData\Entity\Wp'
alias: Wp
I hope this will help anyone in the future!
Hey Tim,
Yeah, your change makes sense too, as long as the paths are not overlapped - it should work well.
I'm glad to hear you found a working solution for you, and thanks for sharing it with others!
Cheers!
Hey, I wanna learn the framework - should I worry that Symfony 5 course has more videos?
Should I start with this one, and then check out topics that were covered in that course, or just go with this one and don't worry about that at all?
Hey Kamil,
If you want to start from scratch a new project - I would recommend to start with this Symfony 6 course. Btw, we're working on Symfony 7 intro course that will be started releasing soon, but you can definitely start with this one to not wait it. And yes, you can watch everything in this track, and fall back to the previous Symfony version to look for more content - it may have some differences, but usually we add video and script notes to mention it.
But in case you're planning to maintain a legacy Symfony version - thats probably a good idea to start with the version you will have to maintain for simplicity.
Cheers!
Has the way symfony console works changed since the filming of this tutorial? Running symfony new mixed_vinyl
generates a different set of files to the ones show in the video. Running git show --name-only
results in:
composer.json
composer.lock
config/bundles.php
symfony.lock
vendor/autoload.php
vendor/autoload_runtime.php
vendor/bin/patch-type-declarations
vendor/bin/var-dump-server
vendor/bin/yaml-lint
vendor/composer/ClassLoader.php
vendor/composer/InstalledVersions.php
vendor/composer/LICENSE
vendor/composer/autoload_classmap.php
vendor/composer/autoload_files.php
vendor/composer/autoload_namespaces.php
vendor/composer/autoload_psr4.php
vendor/composer/autoload_real.php
vendor/composer/autoload_static.php
vendor/composer/installed.json
vendor/composer/installed.php
vendor/composer/platform_check.php
vendor/psr/cache
vendor/psr/container
vendor/psr/event-dispatcher
vendor/psr/log
vendor/symfony/cache
and running symfony serve
give a "Page not found" message when visiting https://127.0.0.1:8000/
What commands need to be run so that I can follow along with this tutorial?
Symfony cli version: 5.5.6
Hey Danny,
First of all, we do recommend you to download the course code for this course on any video page - see "Download" button - and start from the start/ directory there. You will also find a README.md file inside with the detailed instructions about what command you need to run to bootstrap the course project locally. This way you will have the exact same versions we use in this course.
But if you want to follow this course on a newer Symfony version - that's up to you! But keep in mind some changes, depends on the version difference. Also, make sure you allow Composer to execute some plugins - otherwise Symfony Flex will not able to execute some recipes of dependencies and you really may miss some files unless copy/paste them manually.
Cheers!
Cheers!
Just for suggestion, ın installation part, there is a link . BUt that link does not show PHP version requirement.
Hey Mahmut,
Are you talking about this Symfony CLI download link? https://symfony.com/download Or what PHP version requirement are you talking about? Could you explain more please?
Cheers!
Hi Dear Victor,
I am really happy to see your message. Such community is realy nice to imrove ourselves.
For this topic, yes I mentioned that link. Actually, when we follow videos, I am not ( since I am junior, newbie) able to create projects well. I read other documentations about symfony then I was successfull.
Maybe if there can be step by step installation and requirements , will be perfect. because when I follow this video, ı was not aware of php version . so for example, maybe we can mention how to run on apache web server under /var/www/html etc.
other problem for example that ı encounter, I was doing my project in centos and ı needed to create .htaccess file to run my route.
Because http://172.22.111.7/index.bgp/my_route was working but http://172.22.111.7/my_route did not work etc.
thank you regards,
Hey Mahmut,
Thank you for your feedback! Yes, we do not talk about running this website on a real web server like Apache etc. mostly because Symfony makes it much simpler with the built-in web server we show in this course. Topic about running Symfony websites on a real web server deserves a separate course. Mostly, it's about production because configuring it for using locally does not make much sense thanks to the Symfony built-in web server. If you're looking into deploying a Symfony app to production - we have a separate course about it, see it here: https://symfonycasts.com/screencast/ansistrano - but mostly we talk about Nginx there instead of Apache, that is more "mainstream" lately :) Also, you can read more about recommended web server config in the official Symfony docs: https://symfony.com/doc/current/setup/web_server_configuration.html
About PHP version - yeah, we might not mention it in the video probably.. but you can see the minimum required PHP version for this course code on the "Versions" tab below the video on every video page - there's an actual composer.json file with all the main dependencies versions including PHP.
So, this is an intro course about Symfony, so we definitely don't want to complicate things too much for people who just want to start getting acquainted with Symfony, that topic deserve a separate more specific course :)
Btw, every course project code you downloaded will have a README file with all the necessary instructions what you have to boot the course project locally. If you miss it - that makes sense it was hard to configure the project locally for you.
Anyway, good catch on official Symfony docs. That's also a good spot to know more about Symfony, and it covers much more things that were not mentioned in the course.
I hope this helps!
Cheers!
My webserver is returning a 404 - what on earth?
loading (as per command line):
https://127.0.0.1:8000
running symfony serve -d
chrome and firefox give "This site can’t be reached"
I looked at the files, they all apear to be there.
is there a troubleshooting guide for this or a way to find the issue?
ok, I just tried localhost (instead of 127....) and it worked. that's weird.
Hey Cameron,
Happy to hear you were able to find a workaround yourself, great job!
Yeah, sometimes it might be important, especially when you use Docker, or Windows also can give you some issues like this. What OS are you on btw?
I suppose if localhost works for you - great, just use it further. Btw, when you start the Symfony web server, i.e. run symfony serve
- it should output you the correct URL. I wonder, if that a localhost URL or https://127.0.0.1:8000 for you?
I'm on windows 11, using WSL ubuntu. yes, it shows 127.0.0.1:800 - weird? thanks for the help.
Hey Cameron,
Ah, Windows + WSL, that makes sense unfortunately, I heard that has some problems with 127.0.0.1 and you have to use localhost instead. I think nothing much you can do with it, just remember to use localhost instead :)
Cheers!
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.
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!
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?
You can install it manually by moving the binary to a program folder such as this:
C:\Users\%USERNAME%\AppData\Local\Programs
Then copy the path to the folder where the .exe is and add it to your PATH
Windows > Search "env" > Edit the system environment variables > Edit Variables > Select "Path" > Add New > Paste and Apply
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!
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.
how fix the url character encoding? in the browser the url appears "https:\/\/symfonycast.s3.amazonaws.com\/sample.mp3"
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
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!
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!
Yo Cesar!
- 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?
- 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!
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`
Solved it. If anyone finds the same issue, this is what I had to do.
- Move the /usr/bin/ directory in the
/etc/environment
file BEFORE the/usr/local/bin/
and logout and login to terminal again. - After this, the symfony command works, but I got some PHP deprecations and dependency errors when running symfony new project_name.
- 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
- 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.
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.
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!
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.
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?
"Houston: no signs of life"
Start the conversation!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.1",
"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.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.4
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.4.3", // v6.4.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
}
}
Thank you for this tutorial and all the content !
Merci beaucoup pour ce travail et toutes ces informations !
Vincent