Reputation: 195
The following files app and app.dev files is from production environment
app.php file
<?php
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$kernel->handle(Request::createFromGlobals())->send();
//header("Location: maintainance.php");
The following file app.dev files is from production environment. When i set AppKernel in app.dev.php to true and prod to false in app.php file then 404 page works. But It is not working when I do prod= true and dev= false.
app_dev.php
<?php
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// 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',
// '::1',
//))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('dev', false);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();
Kindly help me out..
This is .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.xyz\.com [NC]
RewriteRule ^(.*)$ http://www.xyz.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
Upvotes: 0
Views: 1810
Reputation: 701
If "not working in Prod environment in Symfony2" mean's that your custom 404 page show's in development mode but doesn't in production, that mean's that one reason is around production cache.
Since the prod environment is optimized for speed; the configuration, routing and Twig templates are compiled into flat PHP classes and cached.
So, when your develop your project, all files are stored in not compiled and cached format, and your production environment doesn't know about any changes.
To apply all changes you should clear production cache with command line environment:
$ php bin/console cache:clear --env=prod --no-debug
Upvotes: 0
Reputation: 884
The second parameter in the AppKernel constructor defines, if debugging should be enabled or not. If debugging is enabled, the 404 page usually doesn't work - instead, you get the symfony 2 debugging output.
TL;DR: This should do the trick:
$kernel = new AppKernel('prod', false);
Upvotes: 1