Tom
Tom

Reputation: 1223

Symfony 4 debug production environments

how to debug Symfony 4 project on production environment? I mean in a way that only I from particular IP can do it. In Symfony 2/3 I have app_dev.php controller. How to do this with Symfony 4 and Apache? If I change in .env or via VirtualHost APP_ENV to dev then all app users will see debug toolbar, exception logs etc.

Upvotes: 5

Views: 10780

Answers (4)

Hokusai
Hokusai

Reputation: 2349

I don't recommend using the profiler in a production environment although with Apache you could "emulate" Symfony 2 - 3 behaviour if you configure like this:

<VirtualHost *:80>
...
DocumentRoot "/yourRootDirectory"

<Directory "/yourRootDirectory/">
    DirectoryIndex index.php
    Require all granted
</Directory>       

...

SetEnvIf Request_URI ^/app_dev.php APP_ENV=dev           

Alias /app_dev.php "/yourRootDirectory/"
<Location "/app_dev.php">        
    Require local
</Location>
...        
</VirtualHost>

Requesting http://localhost/app_dev.php from localhost machine you get your app in Symfony 4, 5 in dev mode with profiler like in Symfony 2, 3.

Special attention to Require local for your alias, also you could to use Require ip 192.168.1.1 127.0.0.1 or the IPs you want (see Apache docs). But be careful to expose the dev environment to an ip or computer that is not under your control.

Upvotes: 1

Sean Bahrami
Sean Bahrami

Reputation: 161

This is a little bit of a broad question.

The best way is to use a logging tool like monolog, default output directory is project/var/log/env.log.

As why you are seeing all app users will see debug toolbar, exception logs etc. has to do with your environment settings.

Symfony 4 environment settings work as follows, load config/packages/(env)/package.yaml then load default/production configurations config/packages/package.yaml(if exists). When you set your env dev you are loading config/packages/dev/web_profiler.yaml and in production, there is no definition for that plugin which defaults to not showing up.

Here is more information about environment setup in symfony 4 .https://symfony.com/doc/current/configuration/environments.html

Upvotes: 0

VolCh
VolCh

Reputation: 369

Symfony environment configured by system environment variables. So just add in apache app config (.htaccess by default) something like SetEnvIf Remote_Addr "127.0.0.1" APP_ENV=dev APP_DEBUG=1 (needs https://httpd.apache.org/docs/trunk/mod/mod_setenvif.html)

Upvotes: 2

Gaylord.P
Gaylord.P

Reputation: 1468

You can copy/paste index.php for dev.php and change :

//$env = $_SERVER['APP_ENV'] ?? 'dev';
$env = 'dev';

http://yourwebsite.com/dev.php/

You can restrict for you IP or delete after your actions.

Upvotes: 3

Related Questions