Symfony only logging for dev environment while running in prod mode - symfony

I am using a PaaS provider (cloudControl) for my Symfony app. Works fine in general.
But funny thing: In the app/logs directory, there is only a dev.log. Can someone explain what is wrong here?
(I surely didn't call the app_dev.php, which is by the way not possible on reomte systems - if app_dev.php isn't configured elsewise.)

Look into your web/app.php, it should be:
//...
$kernel = new AppKernel('prod', false);
//...
You probably have new AppKernel('dev', false);

Related

Symfony Url Path

I work with Symfony 2.8 and testing with the built-in php web server.
My Problem is, if I want to open my Webpage I have to use the url:
localhost:8000/app_dev.php
After I build in the translator, the URL must be:
localhost:8000/app_dev.php/en
And in my Ajax.js files the link to the ajax.php have also be like:
/app_dev.php/<route>
I don't want to write the complete path in the browser and in my files to link.
I like to get directly on my startpage with http://localhost:8000 without typing /app_dev.php/en/login etc...
If you want this behavior just change app.php to use the dev environment. So you don't have to type /app_dev.php and use http://localhost:8000
//$kernel = new AppKernel('prod', false);
$kernel = new AppKernel('dev', true);

symfony production mod not working whit debug=false

I create an application in symfony and run it under prod env. but a bundle has 500 Internal error.
I clear cache but problem was not solved.
Finally I change $kernel = new AppKernel('prod', true); in app.php and problem solved.
but When application has an error it shows full error with debug!!!
How can I solve this probleme?dev env has no error

working dev environment symfony2.3

I'm working with a project symfony version 2.3.6 specifically. The problem is that I make changes in the code but the change is not reflected on the page until the page charge many times. I'm in dev environment. is as if not compile the code every time I load the page. Are not you supposed to be in dev environment should always be compiled? a greeting
Thanks four your answer. I use MAMP and php 5.5.3 and no select cache.
the app_dev is:
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// 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', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
i comment the line //$kernel->loadClassCache(); but the problem no solve.
Symfony caches everything by default, especially Twig. And it's tedious, I know.
Looking at the manual (http://symfony.com/doc/current/book/templating.html) it says:
If you add a template in a new location, you may need to clear your
cache (php app/console cache:clear), even if you are in debug mode.
And so, you need to clear the cache. But attention deleting all, because the user sessions are stored in /cache/dev/sessions. That's another strong limitation: Symfony2 requires a writable filesystem.
There is a radical solution, but your app could get really slow, also in dev mode:
twig:
cache: false
In your config.yml

starting with symfony 2 (app_dev.php works, app.php 404's)

I was following the tutorials for symfony, and have hit a road block.
my setup is the current version of xampp (running on windows), so my apache and php are relatively up to date.
following their "quick tour" here:
http://symfony.com/doc/current/quick_tour/the_big_picture.html
everything worked great in the development environment. following the guides a little further however, i started creating my own test bundle via the guide here:
http://symfony.com/doc/current/book/page_creation.html
and can't get it to work properly on the production environment. (it works fine in the dev environment, just like the pre-installed demos did.
i have tried clearing the cache via the php app/console cache:clear --env=prod --no-debug command, however that did not help (and also seems to be the only suggestion that pops up upon searching.
when viewing the routes, i can see that my "/hello/{name}" route is showing up fine on the list of routes.
my app/config/routing.yml has:
acme_hello:
resource: "#AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
as it should, and then my src/Acme/HelloBundle/Resources/config/routing.yml has
hello:
path: /hello/{name}
defaults: { _controller: AcmeHelloBundle:Hello:index }
does anyone have any suggestions as to what the problem might be? (i have also tried converting the out of the box demo to a production route, by copying the route info from the routing_dev.yml file and reassigning the bundle in the appkernel.php file, but that had the same problem)
---edit---
per request, here is my appkernel.php file
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
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 Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Acme\HelloBundle\AcmeHelloBundle(),
new Acme\DemoBundle\AcmeDemoBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
---2nd edit---
i found the problem. i thought it was strange that nothing was showing up in the prod log, so i thought maybe something was redirecting me, causing me to miss the app.php file entirely.
it turns out, this was the problem. i emptied the contents of the .htaccess file that was in the web folder (the one that symfony came preconfigured with) and then everything magically started working.
I also had the same problem. I share how I solved it (Strange but it works).
In file web/app.php change:
$kernel = new AppKernel('prod', false);
by
$kernel = new AppKernel('prod', true); // Enable debug mode
Then load the page in the browser (in app environment) and change the file again disabling debug:
$kernel = new AppKernel('prod', false);
Try loading the page in the browser again. It should work properly.
Best regards,
If you are like me, just want to get the sample application from the tutorial to run in Apache, then this may help you.
I ran into the same problem with version 2.5 just now, and finally found the answer here:
http://symfony.com/doc/current/quick_tour/the_big_picture.html
The demo routes in our application are only available in the dev environment.
Therefore, if you try to access the .../app.php/... URL, you'll get a 404 error.
The easiest way to get it to work is to use app_dev.php instead of app.php.
Just edit .htaccess and change all occurrences of app.php to app_dev.php, like this:
Line 6:
DirectoryIndex app_dev.php
Line 41:
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
Did you try to warm up your cache for the prod environment? You can do this by running the following command:
php app/console cache:warmup --env=prod --no-debug
Also you could check your routes by running
php app/console router:debug
If you want to get specific information on a route you can do php app/console router:debug yourRouteName. But maybe thats what you meant with "viewing the routes".
Another hint has to do with Assets.
Usually if you move your app from dev to prod environment you have to run the following commands:
php app/console assets:install web_directory
php app/console assetic:dump web_directory
Assetic:dump physically genereates your assets, like css stylesheets or javascript files. Something to read about this in detail is here
Perhaps you could edit your post and post your AppKernel.php? Maybe the bundle isn't activated there?
i found the problem. i thought it was strange that nothing was showing up in the prod log, so i thought maybe something was redirecting me, causing me to miss the app.php file entirely.
it turns out, this was the problem. i emptied the contents of the .htaccess file that was in the web folder (the one that symfony came preconfigured with) and then everything magically started working.
For me this problem was caused by cache. After clearing the cache, the new route worked fine on prod environmment (app.php), no 404's.
I ran into the same problem. I fixed the issue by first clearing the cache from the command line using the following command:
php app/console cache:clear --env=prod
After this, I removed the cache folder itself from the app directory (as I couldn't still access my bundle but only the default Symfony homepage) and then refreshed the browser and the error was gone. Hope this helps.

Why does Symfony2 set the error_reporting?

I've been trying to remove the E_NOTICE and E_STRICT error levels to avoid this error:
Runtime Notice: Only variables should be passed by reference
I tried modifying php.ini but didn't work, error_reporting always is -1. Then I tried setting it dynamically in the current action, and worked fine. Then I also tried the same in the first line in app_dev.php and didn't work. Which means Symfony2 is setting it dynamically somewhere.
What should I do?
EDIT
For those who are not familiar with the error:
$user = $this->('security.context')->getToken()->getUser();
$first = reset($user->getRoles()); // error
$roles = $user->getRoles();
$first = reset($roles); // works fine
Whilst the notice is not 'retarded', this is a reasonable question in other contexts so: this is set in the Kernel instance, instantiated in app_dev.php (or app.php).
The second parameter to the construct is a boolean debug flag, and if true then error_reporting is set to -1 and display_errors to 1, otherwise default and 0 respectively.
$kernel = new AppKernel('dev', false);
symfony documentation
Hope this helps.
I got the same error in the following scenario i.e.
Scenario:
I lost the development environment for my existing LIVE project. But I got the whole code from GIT repo and then installed the symfony 2.4.2 (same version as on LIVE site) in my new development environment. Then I found that the web-application pages working on the LIVE site are broken in my new DEV environment.
Solution:
I spent quit a lot time to understand why the problem is then I found that i.e.
When I installed symfony 2.4.2 in my development environment using composer.phar then it created a new web/app_dev.php file in my development environment and it has the following entry to turn it off i.e.
Debug::enable();
Just comment the above line then the php notices will be off and then all the pages that were giving me notices are fixed.
I hope this will be helpful for someone having the same problem like me. Good Luck!
Cheers.
PS: But I will recommend to enable the above line in your new development projects so that you can see the PHP notices and then remove them during development.

Resources