4 min read

How to create a Symfony PHP framework project

This blog article will show you how you could easily create a Symfony PHP framework project through the Symfony installer or Composer. Interested? Read this article right now!

Symfony has four different ways on how you could create a project. In find using the Symfony installer or the Composer installer the easiest ways. I’ll be showing how you can create a project through both of them on Mac, Linux and Windows.

Symfony installer

When you want to use the Symfony installer, a Binary need to be created. Therefore, we need to perform the following command depending on your operating system:

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

// Linux
wget https://get.symfony.com/cli/installer -O - | bash

// Windows
Download the setup.exe right here -> https://get.symfony.com/cli/setup.exe

As the URL from the Symfony installer implies, this will pull in Symfony’s CLI installer, which allows you to install a Symfony project through the CLI. When you perform the command, you will see that it asks you to configure Symfony on your local system. I prefer to add a path to my configuration file, so copy the following line:

export PATH=”$HOME/.symfony/bin:$PATH”

Open a new tab inside the CLI, since we need to access the hidden bashrc file inside the root of our operating system:

nano ./bashrc

Paste the link that we copied at the bottom of the bashrc file.

If we save our ./bashrc file, we are ready to create our first project. In order to create a new project, you got to write down the keyword symfony, followed with the keyword new, followed with the directory name. In our case, let’s call it symfonyapp. Be aware that this will be your project name.

symfony new symfonyapp

You have the option to pass in a --full flag which will install all packages that you need to build web application, be aware that the size of your project will be a lot bigger than performing the command without the --full flag.

symfony new symfonyapp --full

Changing project version

You also have the option to change up your version number as well. If you perform the symfony new symfonyapp command, Symfony will always pull in a project with the most up to date version number. You can change this up by adding a --version={VERSION_NUMBER} flag to it.

symfony new symfonyapp –version=4.0

This command will install a Symfony project with a version number of 5.0.

Composer installer

The second method is to install Symfony through Composer. Make sure that you have Composer installed on your local machine before you perform the following command, otherwise it will not recognize the keyword composer. Once you have installed Composer, you are ready to create your Symfony project by performing the following command:

composer create-project symfony/skeleton symfonyapp

Check if settings are OK

Symfony offers a command which allows you to check whether your Symfony project has been installed successfully. When performing the command, you have to be located inside the Symfony directory that we created above. Let’s change directories.

cd symfonyapp

If you are not sure if you got the right requirements for your Symfony project, you can run the following command to see if your local machine meets the requirements.

symfony check:requirements

If you have your environment setup correctly, you will be hit with the following message:

Your system is ready to run Symfony projects

Open project in the browser

Symfony’s CLI comes with a web server that is very easy to use, which can be used by running the following command inside the project directory:

symfony server:start 

This will return back a message which says that your web server is indeed listening, and it can be accessed through your localhost.

[OK] Web server listening
	The web server is using PHP FPM 8.0.6 is the standard ipv4 address for projects that run on localhost and :8000 is the first available port.

You can copy the link and paste it inside the browser, or you can perform the following command which will open it directly in the browser through the CLI:

symfony open:local

Conclusion 🚀

I hope that this article gave you a clear understanding of how easy it is to create a Symfony project through the Symfony installer or Composer.

If you did enjoy reading this post and you want me to create an article on a topic you like, please send an email to info@darynazar.com.