.. index:: single: Installing and Setting up Symfony
This article explains how to install Symfony and solve the most common issues that may appear during the installation process.
.. seealso:: Do you prefer video tutorials? Check out the `Joyful Development with Symfony`_ screencast series from KnpUniversity.
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 :doc:`installing Composer globally </setup/composer>`. Then, execute this command to create a new empty Symfony application based on its latest stable version:
$ 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:
# 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 :doc:`Symfony Release process </contributing/community/releases>` to better understand why there are several Symfony versions and which one to use for your projects.
On production servers, Symfony applications use web servers such as Apache or Nginx (see :doc:`configuring a web server to run Symfony </setup/web_server_configuration>`). 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, :doc:`install the Symfony Web Server </setup/built_in_web_server>` and then, execute this command:
$ 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 :doc:`/setup/web_server_configuration`.
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:
$ 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:
$ composer remove req-checker
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):
$ cd my_project_name/
$ composer update
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:
# 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
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:
$ 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.
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:
$ 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
:
$ cd my-project
$ php bin/console server:start
With setup behind you, it's time to :doc:`Create your first page in Symfony </page_creation>`.
.. toctree:: :hidden: page_creation
.. toctree:: :maxdepth: 1 :glob: setup/homestead setup/new_project_git setup/built_in_web_server setup/web_server_configuration setup/composer setup/*