sgupta1979's avatar

Disabling dev logs with symfony 3.4

Hi all,

I'm working on an existing Symfony 3.4 application deployed in a production environment. The .env file is already set to APP_ENV=prod, but I’m still seeing both prod-YYYY-MM-DD.log and dev-YYYY-MM-DD.log files being generated in var/logs/.

I expected only prod-.log files to be created in production, so I’m confused why dev-.log is also appearing.

Questions: Is there a bin/console command or some way to enforce the production environment globally?

How can I ensure Symfony doesn’t write dev.log in a production environment?

0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! This is a common issue in Symfony 3.4 applications. Here’s what’s likely happening and how to fix it:

Why is dev.log being created in production?

  • Some process or request is still hitting your app in the dev environment.
  • This can happen if:
    • The web server is (sometimes) routing requests to web/app_dev.php instead of web/app.php.
    • Some CLI commands are being run without specifying --env=prod, so they default to dev.
    • A cron job or deployment script is running in the dev environment.

How to fix it

1. Restrict access to app_dev.php in production

Edit your web server configuration to deny access to web/app_dev.php in production. For example, in Apache:

<Files "app_dev.php">
    Require local
</Files>

Or simply delete/rename app_dev.php in production.

2. Check your deployment and cron jobs

Make sure all CLI commands use the --env=prod flag, for example:

php bin/console cache:clear --env=prod

3. Check your web server configuration

Ensure your web server is only routing requests to web/app.php in production.

4. Clear old logs

After making the above changes, you can safely delete any existing dev-YYYY-MM-DD.log files in var/logs/.

rm var/logs/dev-*.log

5. Double-check .env and environment variables

While .env is helpful, Symfony 3.4 primarily uses the APP_ENV environment variable. Make sure your production environment sets APP_ENV=prod at the server level (e.g., in Apache/Nginx config, or system environment).


Summary

  • dev.log is created when something runs in the dev environment.
  • Restrict or remove app_dev.php in production.
  • Always use --env=prod for CLI commands in production.
  • Set APP_ENV=prod at the server/environment level.

If you follow these steps, only prod-YYYY-MM-DD.log files should be created in production.

Please or to participate in this conversation.