Install and set up the Symfony framework

To create a new Symfony application, first make sure you are using PHP7.1 or later and that Componser has been installed. If not installed, first install Componser globally on your system. If you want to use a virtual machine (VM), see Homestead

Create a new project by running the following command:

$ composer create-project symfony/website-skeleton my-project

This will create a new my-project directory, download the required dependencies, and even generate the basic directories and files you need. In other words, your new app is ready!

Website-Skeleton is optimized for traditional Web applications. If you want to build a microservice, console application, or API, consider using the simpler skeleton project Skeleton:

$ composer create-project symfony/skeleton my-project
$ cd my-project
$ composer require symfony/web-server-bundle --dev

Run the Symfony application

In a production environment, you should use mature Web servers like Nginx and Apache. But for the development environment, using the Symfony PHP Web server is much easier.

Enter the newly created project directory and start the service:

$ cd my-project
$ php bin/console server:run

Open a browser and visit http://localhost:8000/. If all is well, you will see the welcome page. Later, when you are finished, press Ctrl + C in the terminal to stop the service.

If you have any problems running Symfony, your system may be missing some of the necessary technical requirements. Use the Symfony Requirements Checker tool to make sure your system is set up.

If you are using a VM, you may need to bind the server to all IP addresses:

$ php bin/console server:start

Store the project in Git

It’s easy to store your projects on services like GitHub, GitLab, and BitBucket! Once you have initialized a new repository with Git, you can push your commit to the remote end:

$ git init
$ git add .
$ git commit -m "Initial commit"

A reasonable.gitignore file already exists in your project. As you install more packages, the Flex tool will add more content to the file in due course.

Set up the existing Symfony project

If you are using an existing Symfony application, there are only a few things you need to do to complete the project setup. Assuming your team uses Git, you can set up the project using the following command:

// clone the project to download its contents
$ cd projects/
$ git clone ...

// make Composer install the project's dependencies into vendor/
$ cd my-project/
$ composer install

You may also need to customize.env and perform some other project-specific tasks (for example, creating a database).

Check for security vulnerabilities

Symfony provides a utility called Security Checker to check if your project’s dependencies contain any known Security vulnerabilities. Run the following command to install it into the application:

$ cd my-project/
$ composer require sensiolabs/security-checker --dev

From now on, this utility will run automatically whenever you install or update any dependencies in your application. If the dependency contains vulnerabilities, you will see clear messages.

Symfony Demo application

The Symfony Demo application is a full-featured application that shows recommended methods for developing Symfony applications. Symfony is a great learning tool for Symfony beginners, and its code contains plenty of comments and helpful documentation.

To view the code and install it locally, see symfony/symfony-demo

Start Coding!

With your previous Settings in place, it’s time to create your first page in Symfony.