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
devenvironment. - This can happen if:
- The web server is (sometimes) routing requests to
web/app_dev.phpinstead ofweb/app.php. - Some CLI commands are being run without specifying
--env=prod, so they default todev. - A cron job or deployment script is running in the
devenvironment.
- The web server is (sometimes) routing requests to
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.logis created when something runs in thedevenvironment.- Restrict or remove
app_dev.phpin production. - Always use
--env=prodfor CLI commands in production. - Set
APP_ENV=prodat the server/environment level.
If you follow these steps, only prod-YYYY-MM-DD.log files should be created in production.