Chapters
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
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.
Go Deeper!
Watch our Blackfire.io: Revealing Performance Secrets with Profiling course to learn about Blackfire.
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.
127 Comments
Hey Juan,
Hm, yeah, sounds like permissions issue. What command did you run exactly to fix the permissions? Could you try "sudo chmod -R 777 var/cache/" and "sudo chmod -R 777 var/log/"? Does it help? If no - I wonder what OS do you run? Also, do you use Docker or other virtulatization tool for running this project? Probably there's a better path where you could put that project?
Cheers!
Hello!! Thank you very much for the directions. I was able to fix it. After several formulas, changing permissions of different folders and investigating solutions, I changed my project directory and removed the synchronization that it had with Google Drive and it could work for me. I don't know if this had anything to do with the problem. Thank you very much!!
Hey Juanma,
I'm happy to hear to works for you now! Yeah, syncing with G Drive might cause problems, as it may lock files, but not 100% sure, anyway, it's redundant for projects, as your projects should live in Git repo on e.g. GitHub.
Cheers!
Hello.
I can not install the Symfony 5 version.
This commando install the version 4.4.20:
curl -sS https://get.symfony.com/cli... | bash
Using bin/console status I read:
Version 4.4.20
Any help?
Thank you.
Hey Juan S.
How did you create your project? By default it should install the latest release of Symfony, which makes me wonder if you're using an old PHP version (By old I mean lower than 7.2)
Cheers!
Hello, and thank you for your reply.
Yes, at the beginning I thought it was a problem with the php version, because the PHP installed by default with Mac OS Movaje is PHP 7.1 but after install PHP 7.3.8 and try again the command:
curl -sS https://get.symfony.com/cli... | bash
it continues installing Symfony 4.4.20.
Follow you can read the commands that I have executed:
This is the output of php-v:
---- Begin ----
iMac-de-Juan:~ sebastian$ php -v
PHP 7.3.8 (cli) (built: Aug 11 2019 20:50:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
---- End ----
This is the output of curl -sS https://get.symfony.com/cli... | bash
---- Begin ----
iMac-de-Juan:~ sebastian$ curl -sS https://get.symfony.com/cli... | bash
Symfony CLI installer
Environment check
[*] cURL is installed
[*] Gzip is installed
[*] Git is installed
[*] Your architecture (amd64) is supported
Download
Finding the latest version (platform: "darwin_amd64")...
Downloading version 4.23.2 (https://github.com/symfony/......
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 631 100 631 0 0 453 0 0:00:01 0:00:01 --:--:-- 1638
100 8474k 100 8474k 0 0 4321k 0 0:00:01 0:00:01 --:--:-- 4321k
Uncompress binary...
Making the binary executable...
Installing the binary into your home directory...
The binary was saved to: /Users/sebastian/.symfony/bin/symfony
The Symfony CLI v4.23.2 was installed successfully!
Use it as a local file:
/Users/sebastian/.symfony/bin/symfony
Or add the following line to your shell configuration file:
export PATH="$HOME/.symfony/bin:$PATH"
Or install it globally on your system:
mv /Users/sebastian/.symfony/bin/symfony /usr/local/bin/symfony
Then start a new shell and run 'symfony'
---- End ----
Gracias Diego ;-)
Ahh but you're talking about the Symfony CLI version, not the Symfony framework version. What happens when you run symfony new folder_name
?
De nada Juan! Nos conocemos? :)
Hello Diego
This is the output of the command:
--- Beging output ---
iMac-de-Juan:GitHub sebastian$ symfony new diegotest
* Creating a new Symfony project with Composer
(running /usr/local/bin/composer create-project symfony/skeleton /Users/sebastian/Documents/GitHub/diegotest --no-interaction)
* Setting up the project under Git version control
(running git init /Users/sebastian/Documents/GitHub/diegotest)
[OK] Your project is now ready in /Users/sebastian/Documents/GitHub/diegotest
--- End output ---
After that I execute this command:
symfony console about
--- Begin output ---
-------------------- ----------------------------------
Symfony
-------------------- ----------------------------------
Version 4.4.20
Long-Term Support Yes
End of maintenance 11/2022
End of life 11/2023
-------------------- ----------------------------------
Kernel
-------------------- ----------------------------------
Type App\Kernel
Environment dev
Debug true
Charset UTF-8
Cache directory ./var/cache/dev (212 KiB)
Log directory ./var/log (0 B)
-------------------- ----------------------------------
PHP
-------------------- ----------------------------------
Version 7.1.33
Architecture 64 bits
Intl locale n/a
Timezone UTC (2021-03-11T09:52:03+00:00)
OPcache false
APCu false
Xdebug false
-------------------- ----------------------------------
Environment (.env)
-------------------- ----------------------------------
APP_ENV dev
APP_SECRET 21943794ba47162d8e650223720a6603
-------------------- ----------------------------------
--- END OUTPUT --
I have noticed in this output that It said PHP version 7.1.33. But If I execute php -v in the same directory:
--- BEGIN OUTPUT ---
PHP 7.3.8 (cli) (built: Aug 11 2019 20:50:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
--- END OUTPUT ---
I think maybe I have a problem with the PHP configuration.
I am running Mac OSX Mojave, I can not upgrade to a newer version of OSX because a compatibility issue with a very expensive sound card.
Gracias Diego, creo que no nos conocemos.. yo estoy escribiendo desde Madrid
Hey Juan!
Hmm, that's odd. In theory, Symfony CLI should use the same PHP version as your PHP CLI version. Let's try a couple of things. First run local:php:refresh
and then symfony local:php:list
at the root of your project, this will show a list with all the PHP versions available on your system.
After that, create a .php-version
file and write in there "7.2.15" or any other available version on your system, and then, try to create a new project again.
If nothing works, you can install Symfony manually, you only have to clone the "Skeleton" or "Web-skeleton" repository (https://github.com/symfony/skeleton), and run composer install. Let me know if that worked
Entonces creo que no nos conocemos, yo estoy en México :)
Saludos!
Thank you Diego! Now it works.
After creating the .php-version text file with the PHP version (without quotes) it works.
I had a misunderstanding with Symfony versions. I thought that both CLI version and the Symfony project should have the same version, but now I have noticed that the last version of the Symfony CLI is 4.23.2. And the latest version of the Symfony Framework is 5.2.5.
Can you confirm me this?
I hope this helps other symfony developers.
¡Un fuerte abrazo!
Hey Juan, I'm glad to know that it's working for you now, and yes, Symfony CLI and Symfony framework are two different softwares. Sorry about the double quotes confusion :p
Salud!
I think that's the CLI version number. What does your localhost:8000 screen say?
Hey Mike,
Thanks for this tip! Yeah, keep the Symfony CLI version up to date is always a good idea. For this, just run "symfony self:update" to pull new changes.
Cheers!
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
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
?
It downloads and installs as far as I can tell and tells me to move to use it globally
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!
Diego it tells me I don't have permissions
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.
Hey Nicky S.!
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!
ahh it makes sense now! Try running it with sudo
Sudo symfony?
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
Just sharing my install notes, to keep in line with this tutorial:
-Composer version 2.5.4
- PHP 7.4.3
- OS: Archlinux 6.1.14-1-lts
install project:php74 /usr/bin/composer create-project symfony/skeleton:"5.0.*" cauldron_overflow
Hey Bob19,
Yeah, ideally you need to run the Composer via the specific version of PHP like you did, it should prevent some possible errors.
Cheers!
Hey there,
just started this project again and now i can't start the php server on localhost. Instead i can open it from 127.0.0.1:8000. Is that a problem?
Cheers
Jimmy
Ok, just solved it :-)
Hey Jimmy,
Well, that should not be a problem, but it's odd that you cannot use localhost. Perhaps you need to edit your hosts
file so that localhost
points to 127.0.0.1
Hallo,
I'm can't create an new project due this error: unable to run composer.phar create-project symfony/skeleton C:\Users\shaym\crud_system --no-interaction
can you help me?
Hey @Shayma,
can you run php
or composer
commands directly from your shell?
Cheers!
Hi Vladimir,
Thanks for your respond, Yes I can run composer, but php not apparently, it it sticks, and I don't have any error
That is correct PHP behavior, to test it you should run php -v
Try to run symfony new crud_system -vvv
to look where and why your project creation stucks
Cheers!
Hi,
I did that, but I stil have the same error unable to run composer.phar create-project symfony/skeleton C:\Users\shaym\crud_system --no-interaction
I realy need to fix it before next week :(
B.T.W, the project is created but not compleet
The index is missing!
[Web Server ] Dec 16 09:39:10 |WARN | HTTP unable to detect the front controller, disabling the PHP server error="Passthru script \"/index.php\" does not exist under C:\\Users\\shaym\\crud_system\\: CreateFile C:\\Users\\shaym\\crud_system\\index.php: The system cannot find the file specified."
Now I have tried to create the project from the composer: $ composer create-project symfony/website-skeleton crud_system
And that workd. But is this normal? should I do somthing to fix it?
woh that is weird, ok lets try another way. Remove`
crud_system`
folder completely and try
composer create-project symfony/skeleton:"^5.0" crud_system```
I selected version 5.0 to be in sync with current course, but you may select any version you want depending on your needs
Cheers!
Yeah that works! Thank you so much
But I stil not get it why command symfomy new not working...
That is tricky question, you are using native windows console, probably some paths are misconfigured, as I see it tries to execute phar file, probably that is the issue, but why symfony cli did it this way is mystery and needs a lot of investigation
BTW I'd recommend to use WSL for development on Windows PC it helps a lot =)
Cheers!
Thank you so much!!
I followed the symfony new cmd but I only get the vendor folder, nothing else. Is this the recipe thingy I've been reading about?
Hey, I had the same issue, I fixed that by creating a GitHub account...
Hey @Anthony-I
That's weird. Did you get any errors while trying to create a new project (before you created a GitHub account)?
No errors but I think thats because the command is running with --no-interaction by default.
Yea, that's possible. I guess that you were hitting an API rate limit
Hello Matt,
I had the same issue.
Try to run :
> symfony check:requirements
This command checks if your environnement is ready for Symfony and what are the missing extensions.
In my side I got this message :
[ERROR]
Your system is not ready to run Symfony projects
Fix the following mandatory requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* simplexml_import_dom() must be available
> Install and enable the SimpleXML extension.
So I install SimpleXML extension with : sudo apt-get install php-xml
After this installation, the creation of project work
Hey Matt,
Could you explain a bit more? Are you talking about "symfony" CLI tool you downloaded locally? What command exactly did you run? We do recommend you to follow the course by downloading a course code on a course chapter page (see "Download" button in the top right corner of the page) and start from the start/ directory. That directory has README.md file with instructions you need to follow to bootstrap the project locally.
Cheers!
I had a similar issue, after running "symfony new cauldron_overflow" in my terminal it creates that folder - cauldron_overflow, but all there is inside is:
-vendor folder
-.env
-composer.json
-composer.lock
-symfony.lock
Hey Matt!
Hmm, that is super weird! What is inside the vendor/ directory? Is there a bunch of stuff (like vendor/symfony should have quite a few directories) or is it mostly empty? What about the symfony.lock file? It DOES look like, for some reason, the recipes didn't execute. But I want to prove that first. If you just try the command again, does it work? Or do you get this result every time?
Cheers!
Does anyone know if the default git configuration done when the scripts initialize the repository works with GitHub's SSH and GPG keys, I am having trouble doing the initial push to my account.
"Houston: no signs of life"
Start the conversation!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.3.0 || ^8.0.0",
"ext-ctype": "*",
"ext-iconv": "*",
"easycorp/easy-log-handler": "^1.0.7", // v1.0.9
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"symfony/asset": "5.0.*", // v5.0.11
"symfony/console": "5.0.*", // v5.0.11
"symfony/debug-bundle": "5.0.*", // v5.0.11
"symfony/dotenv": "5.0.*", // v5.0.11
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.0.*", // v5.0.11
"symfony/monolog-bundle": "^3.0", // v3.5.0
"symfony/profiler-pack": "*", // v1.0.5
"symfony/routing": "5.1.*", // v5.1.11
"symfony/twig-pack": "^1.0", // v1.0.1
"symfony/var-dumper": "5.0.*", // v5.0.11
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.0.*" // v5.0.11
},
"require-dev": {
"symfony/profiler-pack": "^1.0" // v1.0.5
}
}
Hello. I am following the steps to install symfony and create my first project but when I do the symfony check:req command I get the following error:
[ERROR]
Your system is not ready to run Symfony projects
Fix the following mandatory requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* var/cache/ directory must be writable
> Change the permissions of "var/cache/" directory so that the web
> server can write into it.
* var/log/ directory must be writable
> Change the permissions of "var/log/" directory so that the web
> server can write into it.
I have tried to change the permissions of the file but it keeps giving me the same error. I hope you can give me a solution, thanks.