How to Deploy a Symfony Application
Warning: You are browsing the documentation for Symfony 3.x, which is no longer maintained.
Read the updated version of this page for Symfony 7.0 (the current stable version).
Deploying a Symfony application can be a complex and varied task depending on the setup and the requirements of your application. This article is not a step- by-step guide, but is a general list of the most common requirements and ideas for deployment.
The typical steps taken while deploying a Symfony application include:
- Upload your code to the production server;
- Install your vendor dependencies (typically done via Composer and may be done before uploading);
- Running database migrations or similar tasks to update any changed data structures;
- Clearing (and optionally, warming up) your cache.
A deployment may also include other tasks, such as:
- Tagging a particular version of your code as a release in your source control repository;
- Creating a temporary staging area to build your updated setup "offline";
- Running any tests available to ensure code and/or server stability;
- Removal of any unnecessary files from the
web/directory to keep your production environment clean;
- Clearing of external cache systems (like Memcached or Redis).
There are several ways you can deploy a Symfony application. Start with a few basic deployment strategies and build up from there.
The most basic way of deploying an application is copying the files manually via FTP/SCP (or similar method). This has its disadvantages as you lack control over the system as the upgrade progresses. This method also requires you to take some manual steps after transferring the files (see Common Post-Deployment Tasks)
If you're using source control (e.g. Git or SVN), you can simplify by having your live installation also be a copy of your repository. When you're ready to upgrade it is as simple as fetching the latest updates from your source control system. When using Git, a common approach is to create a tag for each release and check out the appropriate tag on deployment (see Git Tagging).
This makes updating your files easier, but you still need to worry about manually taking other steps (see Common Post-Deployment Tasks).
The specific deployment steps vary greatly from one service provider to another, so check out the dedicated article for the service of your choose:
There are also tools to help ease the pain of deployment. Some of them have been specifically tailored to the requirements of Symfony.
- A Symfony bundle that adds deploy tools to your application.
- This is another native PHP rewrite of Capistrano, with some ready recipes for Symfony.
- An Ansible role that allows you to configure a powerful deploy via YAML files.
- This Capistrano-like deployment tool is built in PHP, and may be easier for PHP developers to extend for their needs.
- This Python-based library provides a basic suite of operations for executing local or remote shell commands and uploading/downloading files.
- Capistrano with Symfony plugin
- Capistrano is a remote server automation and deployment tool written in Ruby. Symfony plugin is a plugin to ease Symfony related tasks, inspired by Capifony (which works only with Capistrano 2).
After deploying your actual source code, there are a number of common things you'll need to do:
Check if your server meets the requirements by running the following command
provided by the
symfony binary created when installing Symfony:
$ symfony check:requirements
Most Symfony applications define configuration parameters in a file called
app/config/parameters.yml. This file should not be deployed, because
Symfony generates it automatically using the
file as a template (that's why
parameters.yml.dist must be committed and
If your application uses environment variables instead of these parameters, you must define those env vars in your production server using the tools provided by your hosting service.
At the very least you need to define the
APP_ENV=prod if you're using Symfony Flex) to run the
prod mode, but depending on your application you may need to
define other env vars too.
Your vendors can be updated before transferring your source code (i.e.
vendor/ directory, then transfer that with your source
code) or afterwards on the server. Either way, just update your vendors
as you normally do:
$ composer install --no-dev --optimize-autoloader
--optimize-autoloader flag improves Composer's autoloader performance
significantly by building a "class map". The
--no-dev flag ensures that
development packages are not installed in the production environment.
If you get a "class not found" error during this step, you may need to
export SYMFONY_ENV=prod (or
export APP_ENV=prod if you're
using Symfony Flex) before running this command so
post-install-cmd scripts run in the
Make sure you clear and warm-up your Symfony cache:
$ php bin/console cache:clear --env=prod --no-debug
While this article covers the technical details of deploying, the full lifecycle of taking code from development up to production may have more steps: deploying to staging, QA (Quality Assurance), running tests, etc.
The use of staging, testing, QA, continuous integration, database migrations and the capability to roll back in case of failure are all strongly advised. There are simple and more complex tools and one can make the deployment as easy (or sophisticated) as your environment requires.
Don't forget that deploying your application also involves updating any dependency (typically via Composer), migrating your database, clearing your cache and other potential things like pushing assets to a CDN (see Common Post-Deployment Tasks).
Symfony applications provide a
kernel.project_dir parameter and a related
You can use this method to perform operations with file paths relative to your
project's root directory. The logic to find that project root directory is based
on the location of the main
If your deployment method doesn't use Composer, you may have removed the
composer.json file and the application won't work on the production server.
The solution is to override the
getProjectDir() method in the application
kernel and return your project's root directory:
1 2 3 4 5 6 7 8 9 10 11
class AppKernel extends Kernel
public function getProjectDir()