4

I've deployed my Symfony2 project to my development server and want to run the dev environment.

Everything is running fine if I use /app.php but if I try app_dev.php I get a 404 error:

The requested URL /app_dev.php was not found on this server.

Below is a copy of my .htaccess file:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^app_dev.php - [L]
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    #RewriteRule ^(.*)$ app.php [QSA,L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

It works fine on my local machine, just not on my development server, any ideas why?

My /cache and /logs directories are both have 777 permissions and are owned by www-data:

drwxrwxrwx+ 4 www-data www-data 4096 Mar 15 11:46 cache
drwxrwxrwx+ 2 www-data www-data 4096 Mar 15 11:05 logs

dev and prod within these directories are exactly the same.

user1961082
  • 1,015
  • 17
  • 41
  • Are you trying to open the dev environment in the dev server from the server itself or from your local computer? – MGP Mar 15 '13 at 12:20
  • I'm browsing to the dev environment (app_dev.php) which is hosted on the dev server from my local computer – user1961082 Mar 15 '13 at 12:39

1 Answers1

7

Check your app_dev.php it has a restriction to deny access to the dev environment from other computers than the server itself.

This is for security reasons, if you deploy to a production server and a user would have access to dev env, then he/she could know a lot about your application.

// 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'], array('127.0.0.1', 'fe80::1', '::1'))
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

You must add your IP to that array, or remove the whole thing (I wouln't recommend that).

Always remember passing the dev variable to AppKernel. $kernel = new AppKernel('dev', true);

MGP
  • 2,981
  • 35
  • 34
  • Thanks @xr09. I have 3 external servers, development, staging and production, would you recommend I use the dev environment on my development server then or not? – user1961082 Mar 15 '13 at 13:03
  • @user1961082 In your dev server is ok (it is made for that after all), but remember setting the rules on deploy to avoid an accident in the production one. – MGP Mar 15 '13 at 13:12
  • so dev env for local machine and development server, test for staging and prod for production? I'm using Capifony with the Capistrano multi-stage extension so can I set this within my development.rb script or do I have to do it directly in app_dev.php? – user1961082 Mar 15 '13 at 13:22
  • 1
    You should edit your app_dev.php to add your local IP, yes dev is for local and dev. server, test is almost the same without the debug toolbar and the verbose logging, check you app/config/config[dev|test].yml and check the differences to see what is enabled in each environment. – MGP Mar 15 '13 at 14:59
  • sorry, when you say add my local IP, do you mean the IP of my local machine rather than the server? I.e whatismyip.com ? – user1961082 Mar 15 '13 at 15:30
  • I'm not sure it's even getting this far because I'm getting a 404 error rather than a 403. I've also tried adding my local IP as well as the dev server IP but still no joy?! – user1961082 Mar 15 '13 at 15:51
  • The apache conf is the same on both? – MGP Mar 15 '13 at 16:38
  • 2
    OK I've realised that app_dev.php is not being deployed. It's within my GIT repository in github but when I deploy using Capifony for some reason it's not pulling this file from github?! – user1961082 Mar 16 '13 at 10:25
  • Yes looks like capifony doesn't deploy those by default, may be this thread will help. https://github.com/everzet/capifony/issues/312 – MGP Mar 18 '13 at 11:59