Installing & Setting up the Symfony Framework

Installing & Setting up the Symfony Framework

This article explains how to install Symfony and solve the most common issues that may appear during the installation process.

Do you prefer video tutorials? Check out the Joyful Development with Symfony screencast series from KnpUniversity.

Creating Symfony Applications

Symfony applications are created with Composer, the package manager used by modern PHP applications. If you don't have Composer installed in your computer, start by installing Composer globally. Then, execute this command to create a new empty Symfony application based on its latest stable version:

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

Tip

If your Internet connection is slow, you may think that Composer is not doing anything. If that's your case, add the -vvv flag to the previous command to display a detailed output of everything that Composer is doing.

If your project needs to be based on a specific Symfony version, use the optional third argument of the create-project command:

1
2
3
4
5
6
7
8
# use the most recent version in any Symfony branch
$ composer create-project symfony/skeleton my-project "3.3.*"

# use a specific Symfony version
$ composer create-project symfony/skeleton my-project "3.3.5"

# use a beta or RC version (useful for testing new Symfony versions)
$ composer create-project symfony/skeleton my-project 3.3.0-BETA1

Note

Read the Symfony Release process to better understand why there are several Symfony versions and which one to use for your projects.

Running the Symfony Application

On production servers, Symfony applications use web servers such as Apache or Nginx (see configuring a web server to run Symfony). However, on your local development machine you can also use the web server provided by Symfony, which in turn uses the built-in web server provided by PHP.

First, install the Symfony Web Server and then, execute this command:

1
$ php bin/console server:run

Open your browser, access the http://localhost:8000/ URL and you'll see the application running. When you are finished working on your Symfony application, stop the server by pressing Ctrl+C from the terminal or command console.

Tip

Symfony's web server is great for developing, but should not be used on production. Instead, use Apache or Nginx. See Configuring a Web Server.

Checking Symfony Requirements

In addition to PHP 7.1, Symfony has other technical requirements that your server must meet. Symfony provides a tool called "Requirements Checker" (or req-checker) to check those requirements:

1
2
$ cd my-project/
$ composer require req-checker

The req-checker utility adds two PHP scripts in your application: bin/check.php and public/check.php. Run the first one in the command console and the second one in the browser. This is needed because PHP can define a different configuration for both the command console and the web server, so you need to check both.

Once you've fixed all the reported issues, uninstall the requirements checker:

1
$ composer remove req-checker

Updating Symfony Applications

At this point, you've created a fully-functional Symfony application! Every Symfony app depends on a number of third-party libraries stored in the vendor/ directory and managed by Composer.

Updating those libraries frequently is a good practice to fix bugs and prevent security vulnerabilities. Execute the update Composer command to update them all at once (this can take up to several minutes to complete depending on the complexity of your project):

1
2
$ cd my_project_name/
$ composer update

Installing an Existing Symfony Application

When working collaboratively in a Symfony application, it's uncommon to create a new Symfony application as explained in the previous sections. Instead, someone else has already created and submitted it to a shared repository.

It's recommended to not submit some files (.env) and directories (vendor/, cache, logs) to the repository, so you'll have to do the following when installing an existing Symfony application:

1
2
3
4
5
6
7
# 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

Checking for Security Vulnerabilities

Symfony provides a utility called "Security Checker" (or sec-checker) to check whether your project's dependencies contain any known security vulnerability. Run this command to install it in your application:

1
2
$ cd my-project/
$ composer require sec-checker

From now on, this command will be run automatically whenever you install or update any dependency in the application.

Installing the Symfony Demo application

The Symfony Demo Application is a fully-functional application that shows the recommended way to develop Symfony applications. It's a great learning tool for Symfony newcomers and its code contains tons of comments and helpful notes.

Run the following command to download and install the Symfony Demo application:

1
$ composer create-project symfony/symfony-demo my-project

Now, enter the my-project/ directory, run the internal web server and browse http://127.0.0.1:8000:

1
2
$ cd my-project
$ php bin/console server:start

Keep Going!

With setup behind you, it's time to Create your first page in Symfony.


This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.