InvalidArgument exception with symfony2 - symfony

When I do app/console cache:clear --env=prod --no-warmup in the console i'm getting the next error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The service definition "security.access.decision_manager" does not exist.
I'm using Symfony2 v2.2.8
I don't use the security.access.decision_manager in my own bundles..
I've searched for security.access.decision_manager in my project but could not find anything from my bundles...
I there also a way to get a backtrace in the console?
The strange thing is, if I do app/console cache:clear --env=dev --no-warmup -v It works fine! And if I do app/console cache:clear --env=prod --no-warmup -v I get that error again..

After debugging hours I've fount the problem!
I was missing the security include in the config_prod.yml
imports:
- { resource: config.yml }
- { resource: parameters_prod.yml }
- { resource: security_prod.yml } <-- The missing one

try next:
rm -rf app/cache/prod/*
rm -rf app/cache/dev/*

Related

How to use app/console command line for Symfony on shared servers?

How to use app/console command line on shared servers?
When I try to flush de cache for example with:
app/console cache:clear -e prod;
I keep getting this kind of errors:
PHP Parse error: syntax error, unexpected 'class' (T_CLASS),
expecting identifier (T_STRING) in
/home/clients/f61b2e8462ca91d597e79838efafc0d1/krown/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php
on line 62
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting
identifier (T_STRING) in
/home/clients/f61b2e8462ca91d597e79838efafc0d1/krown/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php
on line 62
[Symfony\Component\Debug\Exception\FatalErrorException]
Parse Error: syntax error, unexpected 'class' (T_CLASS), expecting
identifier (T_STRING)
In my dedicated server I dont' have this kind of error. The same PHP version (7.1) is installed in both servers.
I was able to solve my issue by forcing the PHP version appending it to all my "app/console" queries, for example:
php-7.1 app/console cache:clear -e prod
php-7.1 app/console cache:clear -e dev
php-7.1 app/console doctrine:generate:entity
php-7.1 app/console doctrine:generate:entities Front
php-7.1 app/console doctrine:schema:update --dump-sql
php-7.1 app/console doctrine:schema:update --force

Sonata admin styles/scripts not loaded with error 403

i have a problem with Sonata Admin bundle. (Symfony version 3.3.11, Sonataadmin 3.24) On localhost everything works fine, but on server all styles and scripts placed in web/bundles/sonataadmin and web/bundles/sonatacore directories is not loaded with error 403. Permission of directories is 777 for folders, 644 for files. How can i fix this problem? Thanks.
Can you try following:
php bin/console cache:clear --env=prod --no-debug
php bin/console assets:install --symlink --env=prod --no-debug
php bin/console assetic:dump --env=prod --no-debug
sudo setfacl -R -m u:www-data:rX path_to_your_project
Do you have result?
I solved this problem by running next command:
php bin/console assets:install

Twig_Error_Loader - directory does not exist

I have this error when deleteing cache.
sudo php app/console cache:clear --env=prod --no-debug
[Twig_Error_Loader]
The "/Users/whitebear/CodingWorks/httproot/myapp/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/Resources/views" directory does not exist ("/Use
rs/whitebear/CodingWorks/httproot/myapp/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/Resources/views").
I deleted all vendor/* and reinstalled by composer, but this error continues.
sudo php app/console cache:clear
This command shows no error.
Remove cache manually - rm -rf var/cache/*
Clean spooled emails rm -rf SPOOL_DIRECTORY/*, by default rm -rf var/spool/*
Both from project root directory.

How to clear Doctrine APC cache for production?

I have this issue when I add a column to one of my entities and release it for production I have to restart Apache in order to clear Doctrine metadata APC/APCU cache.
I have tried all commands below but none worked for me:
php -r "apc_clear_cache();"
php -r "apcu_clear_cache();"
sudo php app/console doctrine:cache:clear-metadata
sudo php app/console doctrine:cache:clear-query
sudo php app/console doctrine:cache:clear-result
I get this error message for --env=prod
sudo php app/console doctrine:cache:clear-metadata --env=prod
sudo php app/console doctrine:cache:clear-query --env=prod
sudo php app/console doctrine:cache:clear-result --env=prod
[LogicException]
Cannot clear APC Cache from Console, its share in the Web server memory and not accessible from the CLI.
The only way I can get it to refresh Doctrine cache is to restart my apache server which can sometimes be an issue.
My cache settings for Doctine in my Symfony project:
doctrine:
orm:
metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc
second_level_cache:
enabled: true
log_enabled: false
region_cache_driver: apc
How can I clear APC cache in this case without restarting Apache each time I release new schema update to production. This is even worse if you have many servers behind a load balancer.
You must understand that Php running under Apache (or Nginx) is different than the Php running via the command line, they are 2 Linux process that cant communicate.
So, even if you can clear the cache via CLI, this will not affect the php under Apache.
The easiest way it to call apcu_clear_cache inside a Symfony controller, or, you can use the Apache Php socket via the CLI.
I recommend to use a tool like http://gordalina.github.io/cachetool/, which do that perfectly.
Instead of trying to clear it from the console, try doing it from a controller or app.php.
I have this line commented in the app.php:
//apcu_clear_cache ();
When I do need to clear the cache, I just uncommented it and load any page. It works for me.
When you run apc_clear_cache(); not from cli but from your app, doctrine cache will be cleared. You can make some button in admin panel, or send curl request to your server after each update to specified file, for example:
http://example.com/apc_cache_clear.php
inside autorize request and clear cache
Take a look at the Smart-Core/AcceleratorCacheBundle Provide a command to clear PHP Accelerator cache from CLI.
This can permit to flush the cache as a cli command as:
php app/console cache:accelerator:clear
The doc include also a Capifony's recipe.
Hope this help

Assetic Dump Cannot Locate File

I am currently trying to move my Symfony App from dev to prod. I am running this commandline script to compile my js and css files:
php app/console assetic:dump --watch;
When I do so, I get the following error:
The source file "/Applications/XAMPP/xamppfiles/htdocs/symfonydev/app/../web/assets/js/js/bootstrap/" does not exist.
I have also run this script:
php app/console assetic:dump --env=prod --no-debug
It gives me a whole other bunch of issues which I will put in another post question.
I have run these scripts to see I can find the file that this is happening in:
find . -name '*.html.twig' -exec grep -li 'assets/js/js/bootstrap*' {} \;
find . -name '*.html.twig' -exec grep -li 'js/js/bootstrap*' {} \;
find . -name '*.html.twig' -exec grep -li 'js/bootstrap*' {} \;
They return no values :(
I cannot compile my js files because I keep getting this error. How in the world do I proceed in moving this Symfony2 app! Please assist if you could.
Thanks!
I found the issue, I had some Bundles in Symfony that were incorrectly configured. Then I found a rouge directory that I made waaaaaaay back when and removed it. Once I did that and ran
sudo rm -rf app/cache/* app/logs/*
and then ran
php app/console assetic:dump --env=prod --no-debug
all was well. Thanks for your feedback everyone!

Resources