Reputation: 8355
In Symfony3, when I want to browse the website in DEV environment on the "live" server, I just enter my ip address in /web/app_dev.php
and open http://www.example.com/app_dev.php/
in the browser.
Since in Symfony4, the environment is now set in /.env
, how can I see the DEV environment on the production machine?
EDIT: I'm looking for a solution that works in production, so applying any global changes (like e.g. setting APP_ENV=dev
in /.env
) is not an option.
Upvotes: 2
Views: 1415
Reputation: 1016
At first this is a bad idea and that's why it wasn't possible by default to access app_dev.php on production server (symfony < 4). You're giving a lot of internal information to public and especially to attackers.
From symfony docs:
After you deploy to production, make sure that you cannot access the app_dev.php or config.php scripts (i.e. http://example.com/app_dev.php and http://example.com/config.php). If you can access these, be sure to remove the DEV section from the above configuration.
You should be able to debug most of the things from logs.
But if you really want to do it, you can just remove public/index.php
and create public/app.php
and public/app_dev.php
like it was in symfony 3 and make it work with env variables. - https://github.com/symfony/symfony-standard/tree/3.4/web
EDIT: To be clear: you can just remove public/index.php
, create public/app.php
, public/app_dev.php
(copies of index.php
). And get inspiration from symfony 3 standard edition to adjust it to your needs.
EDIT2: As @Cerad mentioned it's a better idea to have index.php
and index_dev.php
file names (following Symfony4 decisions).
Upvotes: 0
Reputation: 35973
You can change inside your .env
file APP_ENV
to dev like this:
APP_ENV=dev
If you set that variable symfony load the system into dev enviroment because inside Kernel.php there is this line that check that variable:
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? false);
If you want to do it without change .env file you can for example set a variable in the Apache vhost or Nginx FastCgi configuration, based on the URL you are visiting from - such as APP_ENV=/home/user/app-name/dev.env
or on a live server: APP_ENV=/etc/app-name.prod.env
So in this case you have many .env file but you can use rule based on url
Upvotes: 2