{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/11395","labels_url":"https://api.github.com/repos/symfony/symfony/issues/11395/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/11395/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/11395/events","html_url":"https://github.com/symfony/symfony/issues/11395","id":37956452,"number":11395,"title":"[DX] Improving Vagrant support","user":{"login":"javiereguiluz","id":73419,"avatar_url":"https://avatars.githubusercontent.com/u/73419?v=3","gravatar_id":"","url":"https://api.github.com/users/javiereguiluz","html_url":"https://github.com/javiereguiluz","followers_url":"https://api.github.com/users/javiereguiluz/followers","following_url":"https://api.github.com/users/javiereguiluz/following{/other_user}","gists_url":"https://api.github.com/users/javiereguiluz/gists{/gist_id}","starred_url":"https://api.github.com/users/javiereguiluz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javiereguiluz/subscriptions","organizations_url":"https://api.github.com/users/javiereguiluz/orgs","repos_url":"https://api.github.com/users/javiereguiluz/repos","events_url":"https://api.github.com/users/javiereguiluz/events{/privacy}","received_events_url":"https://api.github.com/users/javiereguiluz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/DX","name":"DX","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2014-07-16T07:36:12Z","updated_at":"2015-02-10T13:45:55Z","closed_at":"2015-02-10T13:45:55Z","body":"The problem\r\n-----------\r\n\r\nWhen using Vagrant and Symfony, you'll end up with some problems when trying to\r\naccess `app_dev.php` controller because of the following check:\r\n\r\n```php\r\n// web/app.php\r\nif (isset($_SERVER['HTTP_CLIENT_IP'])\r\n    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])\r\n    || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')\r\n) {\r\n    header('HTTP/1.0 403 Forbidden');\r\n    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');\r\n}\r\n```\r\n\r\nYour Vagrant host IP will always be different from `127.0.0.1` and therefore,\r\nSymfony will prevent you to access `app_dev.php` controller.\r\n\r\n\r\nThe solution\r\n------------\r\n\r\nThe obvious solution is to manually add the host IP (e.g. `192.168.56.1`) to the\r\nprevious condition, but this doesn't look like a professional way to fix this problem.\r\n\r\nAfter talking with @frastel he proposed me the following alternative. We could introduce a new server variable (e.g. `SYMFONY__TRUSTED_HOSTS`) and then, modify the dev controller (the resulting code may be a bit ugly):\r\n\r\n```php\r\nif (isset($_SERVER['HTTP_CLIENT_IP'])\r\n    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])\r\n    || (\r\n        //BC\r\n        !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '192.168.0.1'))\r\n        &&\r\n        // the new way\r\n        (\r\n            isset($_SERVER['SYMFONY__TRUSTED_HOSTS'])\r\n            && !in_array(@$_SERVER['REMOTE_ADDR'], explode(',', $_SERVER['SYMFONY__TRUSTED_HOSTS']))\r\n        )\r\n    )\r\n) {\r\n    header('HTTP/1.0 403 Forbidden');\r\n    exit('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.');\r\n}\r\n```\r\n\r\nThe last step would be to set up this variable with the web server. For instance, if you use nginx:\r\n\r\n```\r\nlocation ~ ^/(app|app_dev|config)\\.php(/|$) {\r\n   ...\r\n   fastcgi_param SYMFONY__TRUSTED_HOSTS 192.168.0.1,192.168.56.1;\r\n   ...\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/73700881","html_url":"https://github.com/symfony/symfony/issues/11395#issuecomment-73700881","issue_url":"https://api.github.com/repos/symfony/symfony/issues/11395","id":73700881,"user":{"login":"fabpot","id":47313,"avatar_url":"https://avatars.githubusercontent.com/u/47313?v=3","gravatar_id":"","url":"https://api.github.com/users/fabpot","html_url":"https://github.com/fabpot","followers_url":"https://api.github.com/users/fabpot/followers","following_url":"https://api.github.com/users/fabpot/following{/other_user}","gists_url":"https://api.github.com/users/fabpot/gists{/gist_id}","starred_url":"https://api.github.com/users/fabpot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabpot/subscriptions","organizations_url":"https://api.github.com/users/fabpot/orgs","repos_url":"https://api.github.com/users/fabpot/repos","events_url":"https://api.github.com/users/fabpot/events{/privacy}","received_events_url":"https://api.github.com/users/fabpot/received_events","type":"User","site_admin":false},"created_at":"2015-02-10T13:45:55Z","updated_at":"2015-02-10T13:45:55Z","body":"Closing this issue as it's outside of the scope of Symfony core anyway. The snippet discussed is in the SE anyway."}}