1
votes

I'm working with Symfony 3.4 and when I host my project I get an issue with a Route, So I have to debug it but When I add /app_dev.php to my domain name I get an error:

You are not allowed to access this file. Check app_dev.php for more information.

Does Symfony prevent a debug tool for the prod with a simple config ?

I tried this solution but it doesn't work form me:

https://stackoverflow.com/a/39289662/7041095

I have done all this changes but toolbar haven't been enabled:

app/AppKernel.php:

public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new MyVendorFOSUserBundle\MyVendorFOSUserBundle(),
        ];

    +        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
    +        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    +        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    +
             if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
                 $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
                 $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();

app/config/config.yml:

 parameters:
     locale: en

+web_profiler:
+    toolbar: true

app/config/routing.yml:

+
+_wdt:
+    resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
+    prefix: /_wdt
+
+_profiler:
+    resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
+    prefix: /_profiler
+
+_errors:
+    resource: '@TwigBundle/Resources/config/routing/errors.xml'
+    prefix: /_error

web/app_dev.php:

//commenting this lines:
+
+// if (isset($_SERVER['HTTP_CLIENT_IP'])
+//     || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
+//     || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
+// ) {
+//     header('HTTP/1.0 403 Forbidden');
+//     exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
+// }

composer.json:

"require": {
    "php": ">=5.5.9",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/orm": "^2.5",
    "friendsofsymfony/user-bundle": "~2.0",
    "incenteev/composer-parameter-handler": "^2.0",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^5.0.0",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.6.4",
    "symfony/symfony": "3.4.*",
    "twig/twig": "^1.0||^2.0",
+    "sensio/generator-bundle": "^3.0",
+    "symfony/phpunit-bridge": "^3.0"
},

1) I make die ($this->getEnvironement()); => prod

2) No toolbar is displayed & When I try mydomain/app_dev.php I get an issue:

 ClassNotFoundException
Attempted to load class "SensioGeneratorBundle" from namespace "Sensio\Bundle\GeneratorBundle".
Did you forget a "use" statement for another namespace?
1

1 Answers

0
votes

If you have enabled the profiler in production like the answer you are linking, then there is need to run the application trough app_dev.php, app.php should work. Make sure in your composer.jsonthey are listed under require and not requre-dev

If for any reason you have to use app_dev.php on a server then you should edit the file and change it's permission

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}