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.
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:
$ composer create-project symfony/skeleton my-project
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
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
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:
$ 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.
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:
$ cd my-project/ $ composer require req-checker
req-checker utility adds two PHP scripts in your application:
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
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):
$ 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 (
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
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.
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:
$ composer create-project symfony/symfony-demo my-project
Now, enter the
my-project/ directory, run the internal web server and
$ cd my-project $ php bin/console server:start
Go Deeper with Setup¶
- Using Symfony with Homestead/Vagrant
- How to Create and Store a Symfony Project in Git
- How to Use PHP's built-in Web Server
- Configuring a Web Server
- Installing Composer
- Upgrading a Third-Party Bundle for a Major Symfony Version
- Setting up or Fixing File Permissions
- Using Symfony Flex to Manage Symfony Applications
- How to Create and Store a Symfony Project in Subversion
- How to Install or Upgrade to the Latest, Unreleased Symfony Version
- Upgrading a Major Version (e.g. 2.7.0 to 3.0.0)
- Upgrading a Minor Version (e.g. 2.5.3 to 2.6.1)
- Upgrading a Patch Version (e.g. 2.6.0 to 2.6.1)
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.