11

I'm trying to get the debug bar in Yii2 to show on my staging server but for some reason it isn't showing.

Here is code from my web.php config file:

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
                                   'class' => 'yii\debug\Module',
                                   'allowedIPs' => ['127.0.0.1','::1','123.45.67.89']
                                   ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}

123.45.67.89 obviously is just an example for the server's real IP.

I get the servers IP by doing:

$host = gethostname();
$server_ip = gethostbyname($host);

If I try and access the debug page by going to:

http://www.example.com/debug/default/index

I get the message: You are not allowed to access this page.

I am sure I had this working before but now it's not working for some reason and I can't figure out why!?

I'm aware there are debug data files (not sure if they will contain any info on why I can't see it) but I am not sure how I can view the data properly?

Brett
  • 19,449
  • 54
  • 157
  • 290
  • Can you access gii? If not, your environment is probably set to PRODUCTION. – topher Aug 31 '15 at 10:51
  • @topher No I cannot access Gii either. But I ran an echo inside `if (YII_ENV_DEV) {` in the `web.php` config file and it outputs, so not sure what the issue is. – Brett Aug 31 '15 at 12:39
  • Might be something to do with the runtime logs: see https://stackoverflow.com/questions/30770524/yii2-not-found-404-unable-to-find-debug-data-tagged-with-5578effb0790c4-13 – Jairus Jun 21 '20 at 23:57

7 Answers7

10

AllowedIPs parameter should contain your ip, check $_SERVER['REMOTE_ADDR'] for it and set it into AllowedIPs. See how gii check access

Tony
  • 5,797
  • 3
  • 26
  • 22
10

i know this is old but it may help someone now since this isn't very clear anywhere on the web.

We used to have this problem a lot when deploying to test and dev servers. Add this to your main-local.php

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'allowedIPs' => ['*']
    ];
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    ];
}

DO NOT DO THIS ON A PRODUCTION SERVER!!!!

Reginald Goolsby
  • 635
  • 8
  • 10
3

Check what you have in your frontend/web/index.php or app/web/index.php

you need

<?php
  defined('YII_DEBUG') or define('YII_DEBUG', true);
  defined('YII_ENV') or define('YII_ENV', 'dev');
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
2

If you have a custom layout, make sure you are calling <?php $this->endBody() ?> before your </body> tag.

Ansari
  • 8,168
  • 2
  • 23
  • 34
2

Make sure your [yii-app-folder]/runtime/debug folder is writeable by the http server (Apache, nginx, etc).

Example:

sudo chown www-data: ./runtime/debug/ -R
arieltools
  • 1,136
  • 3
  • 15
  • 21
0

If you running nginx & php-fpm, I had to restart the service.

sudo service php-fpm restart
Gajen Sunthara
  • 4,470
  • 37
  • 23
0

You could check your /backend/runtime/ directory and make sure its writeable