You are browsing the documentation for Symfony 4.2 which is not maintained anymore.
Consider upgrading your projects to Symfony 5.2.
Installing & Setting up the Symfony Framework
Installing & Setting up the Symfony Framework¶
Do you prefer video tutorials? Check out the Stellar Development with Symfony screencast series.
Before creating your first Symfony application, make sure to meet the following requirements:
- Your server has PHP 7.1 or higher installed (and these PHP extensions which are installed and enabled by default by PHP);
- You have installed Composer, which is used to install PHP packages;
- You have installed the Symfony local web server, which provides all the tools you need to develop your application locally.
Once these requirements are installed, open your terminal and run any of these commands to create the Symfony application:
1 2 3 4 5
# run this if you are building a traditional web application $ symfony new --full my_project # run this if you are building a microservice, console application or API $ symfony new my-project
The only difference between these two commands is the number of packages
--full option installs all the packages that you usually
need to build web applications. Therefore, the installation size will be much bigger.
Both commands 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!
If you can’t use the
symfony command provided by the Symfony local web
server, use the alternative installation commands based on Composer and
displayed on the Symfony download page.
Running your Symfony Application¶
On production, you should use a web server like Nginx or Apache (see configuring a web server to run Symfony). But for development, it’s more convenient to use the Symfony Local Web Server installed earlier.
This local server provides support for HTTP/2, TLS/SSL, automatic generation of security certificates and many other features. It works with any PHP application, not only Symfony projects, so it’s a very useful development tool.
Open your terminal, move into your new project directory and start the local web server as follows:
$ cd my-project/ $ symfony server:start
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 by pressing
Ctrl+C from your terminal.
If you’re having any problems running Symfony, your system may be missing some technical requirements. Use the Symfony Requirements Checker tool to make sure your system is set up.
If you want to use a virtual machine (VM) with Vagrant, check out Homestead.
Storing your Project in git¶
Storing your project in services like GitHub, GitLab and Bitbucket works like with
any other code project! Init a new repository with
Git and you are ready to push
to your remote:
1 2 3
$ git init $ git add . $ git commit -m "Initial commit"
Your project already has a sensible
.gitignore file. And as you install more
packages, a system called Flex will add more lines to
that file when needed.
Setting up an Existing Symfony Project¶
If you’re working on an existing Symfony application, you only need to get the project code and install the dependencies with Composer. Assuming your team uses Git, 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). When working on a existing Symfony app for the first time, it may be useful to run this command which displays information about the app:
$ php bin/console about
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 Use PHP’s built-in Web Server
- Configuring a Web Server
- Upgrading a Third-Party Bundle for a Major Symfony Version
- Setting up or Fixing File Permissions
- Using Symfony Flex to Manage Symfony Applications
- Symfony Local Web Server
- How to Install or Upgrade to the Latest, Unreleased Symfony Version
- Upgrading a Major Version (e.g. 3.4.0 to 4.1.0)
- Upgrading a Minor Version (e.g. 4.0.0 to 4.1.0)
- Upgrading a Patch Version (e.g. 4.1.0 to 4.1.1)
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.