Problems with Symfony 5.1's prod cache and disabling it - symfony

The problem I've been having is that whatever changes I made to twig templates, they never appear on the PROD site without cache:clear commands in console.
There are times when checking rapid iterations on a live site are useful without a lot of shell cache clearing.
This led me to ask, Is there a simple way to temporarily disable Symfony 5.1's PROD caches (so that it works more like DEV caches) on a fairly standard setup?
There are a number of documents such as https://symfony.com/doc/current/reference/configuration/twig.html -- but they didn't really help resolve the issues I've had.

After some further digging and experimentation, I found that changing:
//twig.yaml
twig:
default_path: '%kernel.project_dir%/templates'
cache: 'false'
auto_reload: 'true'
seemed to do the trick, but you still have to cache:clear one further time for it to start working.
I have no idea why this should be necessary, but at least it is functioning as expected now.

Related

Symfony: Prod environment on webserver produces blank page

my Symfony 3 app works flawless on my local webserver. Since it´s been installed on the remote web server it produces a blank page, even the routing doesn't work. After editing web/app.php $kernel = new AppKernel('prod', false); and set it to true, the application works as expected and does not display any errors.
Why does the application behave different on the local and the remote webserver. Did I miss to configure something on the remote server?
Any suggestions?
Thanks in advance!
Finally I have a solution to solve the problem: after the composer update I have to clear the cache of the prod environment manually by executing rm -fr var/cache/prod/*. For whatever reason does the command php bin/console cache:clear --env=prod quit working immediately after the composer update without throwing any error messages. After removing the cache files manually both the application and the cache:clear command work as expected without modifying web/app.php.
1.check permission to cache and log dirs ( need to be 777 )
2.check (paste here) error in logs/prod.log
Since I couldn´t find out what´s the real cause of this problem I´ve made a fresh install of my application and updated Symfony and all dependencies with composer.
Although I did the same with the old installation, it does the trick this time. My guess is, something went wrong with the composer update before.
Thanks again for your help! If someone has a similar problem I would appreciate if you could post how you solved the problem (or why AppKernel['prod'] = 'true' did work).
I have plausible explanation, what might have been the problem.
I have encountered this problem earlier this year with Symfony3, while developing on Windows but deploying manually (copying project's files) to shared server with Linux.
As you say - blank page in prod environment.
To add to the mystery log files did not show any problems
So i enabled dev environment to check what is wrong
application worked as intended if i added app_dev.php in the URL
I overviewed all the files, more than once, but copy was done correctly.
The answer
After some time I "came across" the file: bootstrap.php.cache in var directory. It "felt suspicious".
As I had exhausted my options i just deleted it to test the result.
That solved it in my case.
Site was running again.
No more blank page!
I guess mixed development environment has its toll.

How to debug 500 Error in Symfony 2 and above

I am struggling with Symfony 2 error reporting because I can't find out what really is happing when a 500 Error is triggered.
I have XDebug correctly installed, but it seems like Symfony rules everything.
The custom pages just says:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
That's pretty much funny! Something is broken, but, the fact is that I need to fix my code, but can't know what or where it is the problem! And sure, If I send an email for the Symfony team will they be able to solve my problem once I not even know what to say them?
Some clue on what I am missing here?
For Symfony 2 and below,
First, look at the logs in app/logs depending on your environment — dev.log for development, prod.log for production, etc.
If the code crashes before Symfony has a chance to run, check the logs of your web server — e.g. nginx.
If you have a symfony flex project, it is also possible that you forgot to install monolog ;) Run:
composer req log
For Symfony versions 3.x, 4.x, 5.x, 6.x and above,
The logs will be found depending on the environment
For dev env - var/logs/dev.log
For prod env- var/logs/prod.log
Also, as the accepted answer suggests, you might have to check the server logs if your app crashes before even reaching Symfony.
Usual location for server logs is listed below -
For apache server - ls /var/log/apache2
For Nginx server - ls /var/log/nginx
sudo chmod -R o+w var/cache/
from inside the project's folder,
solved the problem for me, at least this time :)
There were no errors in Symfony's or web server's logs.
What caused the problem
It turned out that the problem was caused by me previously removing the cache folder, and regenerating the cache, i.e.
rm -fr var/cache/
./bin/console cache:clear
After that, var/cache became drwxr-xr-x.
An even better way to improve your Symfony debugging process is to have Monit monitor your Symfony and Apache logs for any errors and send you emails whenever something bad happens: http://intelligentbee.com/blog/2016/01/12/how-to-monitor-symfony-and-apache-logs-with-mmonit/

Symfony2 app not works after cache clear

I'm deploying a Symfony2 app in CentOS server with Cpanel.
First time that I execute the app runs well, but the problem comes When I do cache clear, then app not works more, and put this error.
Class "Propa\PageBundle\Entity\Page" is not a valid entity or mapped super class.
To enter in site: http://propa.estudi83.com/app_dev.php/es/empresa/
What Can I do ?
UPDATE: Resolved the problem was eAccelerator, I'm uninstalled eAccelerator and installed APC and works fine!!
Thanks
Regards
It may be a cache optimizer issue. If you are using eAccelerator, then you will have problems, probably with Doctrine. The reason is eAccelerator removes annotations from the code! You can try APC which performs well with doctrine.
Read apc vs eaccelerator vs xcache

What should I know about php5-fpm as a developer?

So I've recently setup a LEMP server and have managed to work may way through some of the configurations. I'm now to the point where I can begin writing php scripts and building basic pages. Looking at the php5-fpm wiki there aren't any pages discussing any changes I should expect as far as php scripts and such are concerned, only installation/configuration settings.
Is everything beyond the installation/configurations steps business as usual? From the point of view of a php developer what changes should I expect/make? How can best take advantage of the fpm version (in the php code, not module/system configurations)? I'm focused on comparing well-written php in both cases.
When I made the switch myself, I got to know a few perks about this kind of setup, such as APC file upload progress does not work out of the box (and you're better off using something else, such as nginx-progress-upload and/or JS File API); Some header names might have changed (prepending HTTP_); and a new and very useful function called fastcgi_finish_request.
For more information, though, look around the PHP-FPM Manual.
Only major gotcha I can think of is that some functions in the pcntl extensions, such as pcntl_fork, are not supported when running under FPM. (However, they're not supported under mod_php either, so this shouldn't come as too much of a surprise.)

apc under php-fpm not caching files

I currently have apc installed and running under php-fpm. The apc info page reflects user cache entries but the file cache reflects 0 files cached. Other similar threads state that if runnning under FCGI, apc will not share the cache between the worker processes, and recommend using php-fpm. I share the symtoms with these people, however I am already using php-fpm and it is running fine. If anyone has any idea here, would be greatly appriciated. Been stuck on it at work for a couple hours now. I have another box set up where it is working and I believe I followed the same procedure, and both boxes are identical. Not sure where I could have gone wrong. I would be happy to provide more information. Thanks.
Update : When compiling APC with debug, I get file too big errors with every file. This is not the case on the working box. Looking through the source, I found the relevant snippet -
if(APCG(max_file_size) < fileinfo->st_buf.sb.st_size) {
apc_debug("File is too big %s (%d - %ld) - bailing\n" TSRMLS_CC, filename,t,fileinfo->st_buf.sb.st_size);
goto cleanup;
}
It has the correct filesize in the fileinfo strut, so I'm imagining that max_file_size is messed up. I'm going to try and track this down. Anyone have any idea? This is working fine on 64 bit Ubuntu outside of EC2, with identical configuration and files.
All the build tests from source are failing and hardcoding that value in doesn't help, it still doesn't cache.

Resources