Symfony how to switch to production mode

Symfony how to switch to production mode banner

To switch (enable) to production mode, you must change APP_ENV env variable in your .env.local file on your production machine to APP_ENV=prod. Don't forget to change your APP_SECRET as well.

# .env.local

What is Symfony APP_ENV?

In Symfony applications, the APP_ENV variable in the .env file is used to define the environment in which your application is running. The environment can be thought of as a way to categorize the different states or configurations in which your application operates, such as "development," "production," "testing," etc. This concept is not unique to Symfony and is also prevalent in many other web development frameworks.

What if I don't have a .env.local file?

It's possible that you have only a .env file, or maybe However, the recommended Symfony config is to have a .env.local file in your production environment. Preferably, the .env.local file shouldn't be version-controlled. That way, if you have your git repo hacked, your credentials, API keys, etc. won't be exposed. 

What types of web server setups are available for production deployment?

Symfony applications can be deployed to production by using different setups. Here are some of the most popular ones:


Symfony applications can be run on an Apache Web server using either mod_php or php-fpm.

I did a full performance comparison between mod-php vs php-fpm. In my tests, I found out that php-fpm is faster and offers a more stable performance.

Here is a brief pros and cons comparison.


  • PHP interpreter embedded in the web server.
  • Fast but can lead to memory bloat with concurrent requests.
  • Configuration in web server settings.
  • Simpler setup.
  • Vulnerabilities can affect all server processes.

PHP-FPM (FastCGI Process Manager):

  • Separate PHP process manager.
  • Better performance and resource management.
  • Configuration in PHP-FPM settings.
  • Efficient resource utilization.
  • Suitable for high-traffic applications.
  • Isolates PHP processing for better security.

Note that if you are planning to use Symfony with Apache, you'll need to install symfony/apache-pack composer module.


Symfony can run on a Nginx server as well using the PHP-FPM implementation.


Caddy is a relatively new web server, which is written in Go. Again, it can be used to run Symfony applications with the PHP-FPM module.

As you can see, there are essentially only two methods to run a Symfony application in production: Apache mod_php or PHP-FPM.