Installing & Setting up the Symfony Framework
Installing & Setting up the Symfony Framework¶
To create your new Symfony application, first make sure you're using PHP 7.1 or higher and have Composer installed. If you don't, start by installing Composer globally on your system. If you want to use a virtual machine (VM), check out Homestead.
Create your new project by running:
$ composer create-project symfony/skeleton my-project
This will create a new
my-project directory, download some dependencies into
it and even generate the basic directories and files you'll need to get started.
In other words, your new app is ready!
You can also download a specific version of Symfony:
1 2 3 4 5
# use the most recent version in any Symfony branch $ composer create-project symfony/skeleton my-project "3.3.*" # use a beta or RC version (useful for testing new Symfony versions) $ composer create-project symfony/skeleton my-project 3.3.0-BETA1
Some version are long-term support (LTS) versions. Read the Symfony Release process to learn more.
Running your Symfony Application¶
First, move into your new project and install the server:
cd my-project composer require server
To start the server, run:
$ php bin/console server:run
Open your browser and navigate to
http://localhost:8000/. If everything is working,
you'll see a welcome page. Later, when you are finished working, stop the server
Ctrl+C from your terminal.
If you're using a VM, you may need to tell the server to bind to all IP addresses:
$ php bin/console server:start 0.0.0.0:8000
You should NEVER listen to all interfaces on a computer that is directly accessible from the Internet.
Troubleshooting: The Requirements Checker¶
If you're having any problems running Symfony, your system may be missing some technical requirements. Symfony has a "Requirements Checker" tool that you can use to easily make sure your system is set up. First, move into your project directory and install it:
$ composer require req-checker
req-checker utility adds two PHP scripts to your application:
public/check.php. Run the first one
from your terminal:
This will check your CLI environment. Run the second one from a browser (e.g.
http://localhost:8000/check.php) to check your web server environment.
Once you've fixed any issues, uninstall the requirements checker:
$ composer remove req-checker
Setting up an Existing Symfony Project¶
If you're working on an existing Symfony application, you'll just need to do a few things to get your project setup. Assuming your team uses Git, you can setup your project with the following commands:
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
You'll probably also need to customize your .env and do a few other project-specific tasks (e.g. creating database schema).
Checking for Security Vulnerabilities¶
Symfony provides a utility called the "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 utility will be run automatically whenever you install or update any dependency in the application. If a dependency contains a vulnerability, you'll see a clear message.
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.
To check out its code and install it locally, see symfony/symfony-demo.
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.