Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

Creando un Nuevo Proyecto de Symfony 5

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.

Hola Amigos! y bienvenidos al mundo de Symfony 5... el cual resulta ser mi mundo favorito! Ok, quizás Disneylandia es mi mundo favorito... pero programar en Symfony 5 está en segundo lugar...

Symfony 5 es simple y eficiente: es muy veloz, empieza en pequeño, pero crece conforme a tu aplicación. Y esto no es solo jerga de Marketing! Tu aplicación de Symfony literalmente crecerá conforme necesites más funcionalidades. Ya hablaremos de eso más tarde.

Symfony 5 es también el producto de años de trabajo sobre experiencia de desarrollo. Básicamente, la gente detrás de Symfony quiere que ames utilizarlo sin sacrificar calidad. Asi es, escribes código del cual estás orgulloso, amas el proceso, y construyes cosas rápidamente.

Symfony es también el framework más rápido de PHP, lo cual no nos sorprende: - su creador también creó el sistema de análisis de rendimiento de PHP llamado Blackfire. Por lo que el rendimiento siempre está en la mira.

Go Deeper!

Mira nuestro Blackfire.io: Revealing Performance Secrets with Profiling curso sobre Blackfire.

Descargando el instalador de Symfony

Entonces... Manos a la obra! Empieza por abrir http://symfony.com y dar click en "Download". Lo que estamos apunto de descargar no es realmente Symfony. Es un ejecutable que va a hacer que tu experiencia de desarrollo con Symfony sea... Excelente.

Como estoy en una Mac, voy a copiar este comando. para luego abrir una terminal - yo ya tengo una abierta. No importa en donde lo ejecutes. Pégalo!

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

Esto simplemente descarga un archivo ejecutable y, para mi, lo guarda en mi carpeta home. Para poder hacerlo ejecutable en cualquier lugar en el sistema, Voy a seguir el consejo del comando y lo moveré a otro lugar:

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

Ok, inténtalo!

symfony --version

Symfony está vivo! Saluda al CLI de Symfony: una herramienta de linea de comandos que nos va a ayudar con varias cosas a lo largo de nuestro camino hacia la gloria de programación.

Empezando una nueva aplicación de Symfony

Su primer trabajo será ayudarnos en crear un nuevo projecto de Symfony 5. Ejecuta:

symfony new cauldron_overflow

Donde cauldron_overflow será el directorio donde la nueva aplicación vivirá. Este también resulta ser el nombre del sitio que vamos a construir... Pero ya hablaremos de eso más tarde.

Detrás de escenas, este comando no está haciendo nada especial: clona un repositorio de Git llamado symfony/skeleton y luego utiliza Composer para instalar las dependencias del proyecto. Hablaremos más sobre ese repositorio y de Composer un poco más adelante.

Cuando termine, muévete al nuevo directorio:

cd cauldron_overflow

Y luego ábrelo en tu editor favorito. Yo ya lo tengo abierto en mi editor favorito: PhpStorm, solo abre Archivo -> Abrir Directorio y selecciona la carpeta del nuevo proyecto. En fin, saluda a tu totalmente nuevo, brillante, prometedor proyecto de Symfony 5.

Nuestra aplicación es diminuta!

Antes de comenzar a mover aquí y allá, vamos a crear un nuevo repositorio de git y hacer un commit. Pero espera... Ejecuta:

git status

En la rama master, nada por hacer commit.

Sorpresa! El comando new de Symfony ya inicializó el repositorio de Git por nosotros e hizo el primer commit. Puedes verlo tras ejecutar:

git log

Add initial set of files

Perfecto! Aunque, personalmente me hubiera gustado un mensaje ligeramente más épico... pero está bien.

Voy a oprimir "q" para salir.

Mencioné anteriormente que Symfony empieza en pequeño. Para probarlo, podemos ver una lista de todos los archivos agregados en el commit. Tras ejecutar:

git show --name-only

Eso es! Nuestro proyecto, el cual está completamente listo para trabajar con Symfony tiene menos de 15 archivos... si no cuentas archivos como .gitignore. Simple y eficiente.

Revisando los Requerimientos

Conectemos un servidor web a nuestra aplicación y veámoslo en acción! Primero, asegurate que tu computadora tenga todo lo que necesita Symfony al ejecutar:

symfony check:req

Para revisar los requerimientos. Estamos bien - pero si tienes algún problema y necesitas ayuda, menciónalo en los comentarios.

Iniciando el Servidor Web de PHP

Para poner el proyecto en marcha, regresa a PhpStorm. Vamos a hablar más sobre cada directorio pronto. Pero la primer cosa que tienes que saber es que el directorio public/ es el "documento raíz". Esto significa que necesitas apuntar tu servidor web - como Apache o Nginx - a este directorio. Symfony tiene documentación sobre como hacerlo.

Pero! para facilitarnos la vida, en vez de configurar un servidor web en nuestra maquina, podemos usar el servidor integrado de PHP. En la raíz de to proyecto, ejecuta:

php -S 127.0.0.1:8000 -t public/

Tan pronto hacemos eso Podemos regresar a nuestro navegador e ir a http://localhost:8000 para descubrir... Bienvenido a Symfony 5! Ooh, que elegancia!

Siguiente: tan fácil como fue ejecutar ese servidor web de PHP, Voy a mostrarte aun una mejor opción para el desarrollo local. Ahora vamos a conocer el significado de los directorios en nuestra nueva aplicación y asegurarnos de que tenemos algunos plugins instalados en PhpStorm... los cuales hacen trabajar con Symfony todo un placer.

Leave a comment!

123
Login or Register to join the conversation
Juanma C. Avatar
Juanma C. Avatar Juanma C. | posted hace 1 año

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.

1 Reply

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!

Reply
Juanma C. Avatar

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

1 Reply

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!

1 Reply
Juan S. Avatar

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.

1 Reply

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!

1 Reply
Juan S. Avatar

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 ;-)

Reply

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? :)

Reply
Juan S. Avatar

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

Reply

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!

Reply
Juan S. Avatar

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!

Reply

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!

Reply
Leon Avatar

I think that's the CLI version number. What does your localhost:8000 screen say?

Reply

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!

Reply
Default user avatar
Default user avatar Stephen Spittal | posted hace 3 años

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

1 Reply

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?

Reply
Default user avatar
Default user avatar Stephen Spittal | MolloKhan | posted hace 3 años

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

Reply

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!

Reply
Default user avatar
Default user avatar Stephen Spittal | MolloKhan | posted hace 3 años

Diego it tells me I don't have permissions

Reply
Nicky S. Avatar

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.

Reply

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!

Reply

ahh it makes sense now! Try running it with sudo

Reply
Default user avatar
Default user avatar Stephen Spittal | MolloKhan | posted hace 3 años

Sudo symfony?

Reply

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

Reply
Bob19 Avatar

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
Reply

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!

Reply
Jimmy Avatar
Jimmy Avatar Jimmy | posted hace 8 meses | edited

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 :-)

Reply

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

Reply
Default user avatar

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?

Reply

Hey @Shayma,

can you run php or composer commands directly from your shell?

Cheers!

Reply
Shayma N. Avatar

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

Reply

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!

Reply
Shayma N. Avatar

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 :(

Reply
Shayma N. Avatar

B.T.W, the project is created but not compleet

Reply
Shayma N. Avatar

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."

Reply
Shayma N. Avatar

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?

Reply

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!
Reply
Shayma N. Avatar

Yeah that works! Thank you so much

But I stil not get it why command symfomy new not working...

Reply

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!

Reply
Shayma N. Avatar

Thank you so much!!

Reply
Default user avatar

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?

Reply
Mathis Avatar
Mathis Avatar Mathis | Matt | posted hace 11 meses | edited

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

Reply

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!

Reply
Matt Avatar

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

Reply

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!

Reply
Caleb S. Avatar
Caleb S. Avatar Caleb S. | posted hace 1 año

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.

Reply

Hey Caleb S.

Good question! You made me dig for a bit because I was not sure. I found this https://stackoverflow.com/a...
basically, you have to use Github's API V3

I hope it helps, cheers!

Reply
Caleb S. Avatar

Well it turns out I had to create the remote repository on GitHub before I could do this, although I could swear I have done this from the command line in the past. Maybe I am just thinking of branches though.

Reply
Marco P. Avatar
Marco P. Avatar Marco P. | posted hace 2 años

Hello, I have a problem installing symfony cli. Unfortunately I cannot update my Mac as it does not support versions higher than El Capitan. When I try to install symfony cli I get this error: dyld: lazy symbol binding failed: Symbol not found: _clock_gettime
Referenced from: / usr / local / bin / symfony (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib

I believe an older version of symfony cli may work, how do i install it? Thanks so much

Reply
Marco P. Avatar

Hi, I solved! I downloaded the cli-4.23.3 version, renamed the symfony_darwin_amd64 file to symfony, made it executable and copied it to /usr/local/bin. This version works with El Capitan. I hope it will be useful to others. bye

1 Reply
Cat in space

"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.17.5
        "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
    }
}
userVoice