How to configure APC with Symfony2 - symfony

I can't find any documentation as to how to configure APC with Symfony2. I don't want to write any specific code or have anything advanced, just the basic APC setup with Symfony2.
I've uncommented the two lines in app.php and everything seems ok (the site runs for a start).
However...
(1) I hear people talk about "restarting APC" - what does that mean? Can I not just run this any time I want a full clean:
php console cache:clear --env=prod --no-debug
(2) In app/config_prod.yml, I see this:
framework:
router:
strict_requirements: null
#validation:
# cache: apc
...what does uncommenting that do?
It seems too easy just to uncomment the two lines in app.php. SUrely there must be more config options. Again I don't want an advanced setup.
I don't even know if APC is running, but considering the site runs that tells me it is (before it didn't and I needed to install APC in PHP).
When I searched "APC" in the Symfony2 cookbook it returned literally nothing.

apc_clear_cache() will clear the system cache and calling apc_clear_cache('user') will clear the user cache. -> https://stackoverflow.com/a/911219/1501189
also, to get apc up and running in symfony, make sure u enable it in your php.ini for CLI aswell! not only in your php.ini that your apache uses, this had me fooled for a while when i was trying to get this running myself
To check if symfony is using APC, click the profiler at the bottom of the page (when in dev environment), then click config on the left, and it will tell your wether or not APC is enabled

Related

Symfony 4 - Weird errors

I'm currently having a mental breakdown, hitting my head against different walls.
I'm trying to get my app online to prod, and have been trying for weeks now.
I've had this error a lot : Symfony - twig - Autoloader expected class
Now, it's evolved, and I have this :
Sometime, after clearing cache, running composer install / update a dozen time, this error goes away and..... I get the old error again!
Please help if you've ever seen anything like this
How are you making deployment on prod environment?
Maybe there are some files doubled so loader doesn't recognize them correctly?
Some deployment methods dont remove files deleted at project (php storm deploy).
Last times i had error with Twig_Environment. It was after i upgraded my project's Symfony version from 3.3 to 3.4.
To Sf 3.3 all services defined at services.yml at enabled bundles was PUBLIC.
Since 3.4 they are all PRIVATE by default.
What i did was to add some .yml code at every services.yml file i had:
_defaults:
public: true
Without this code Twig_Environment could not see some Twig Extensions and other classes.
Also I have read your last post. So You don't have access to console, yup?
Maybe try to have second instance of Your project (locally) where everything is set up to prod env?
Then try to:
composer dump-autoload -o
And other preparings for prod:
php bin/console a:install --symlink
php bin/console a:dump --env=prod
php bin/console c:c --env=prod
After this You should upload vendor/autoload.php, generated assets, etc. at production server. And this should happen every site update.
It's really bad having Sf project withoud ssh access.

Symfony 2 production env constant errors

I developed my Symfony 2.8 project locally on dev enviroment.
Than i needed to upload it to a server and run it on production.
I did all the steps:
1. Checked it out with git on the server
2. Ran composer install
3. Cleared cache, doctrine cache, installed the assets
4. Configured my database
Saying this ... I`m still getting problems like:
Internel server errors like
No route found for "GET ..
And for some reason it makes requests from time to time to app_dev.php - my ht access clearly states that directory index is app.php and etc
I get double template rendering - the same view is loaded two times - two menu section ... two content section
I am really frustrated, cause ive tried everything i know. Could someone help me, ill provide additional info if needed.
I need any suggestions, ideas and etc that could help me.
My .htaccess file - http://pastebin.com/4XHetMPV
First, try to remove your cache manually and clean your logs :
rm -rf app/cache/* && rm app/logs/prod.log
Then, try to browse a route of your application.
If you still have an error, open your log using cat app/logs/prod.log and find the last error.
If it's a php error caused by a vendor, remove your /vendor directory and run composer update
If you are not able to fix your problem, add to your question the error log and code of the method called by your route that is not working.
As chalasr said, cleaning prod cache manually works after the app.php setup.
I think a command like :
php app/console cache:clear --env=prod --no-debug
should work too.

How to permanently resolve Symfony2 twig_upper_filter error?

Situation:
Production mode
Change a file
One of the pages on the site returns the following 500 internal error.
Run composer update, and the error goes away.
Change a file and the problem returns.
The code calling the twig_upper_filter is buried deep inside the now embedded in symfony bootstrap templates.
What does composer update do that might fix this? It is repeatable (on one server only).
UndefinedFunctionException: "Attempted to call function
"twig_upper_filter" from the global namespace." at
Symfony 2.6.
Because at the end of composer update it does a cache clear, everytime you change something somewhere you need to clear the cache for the change to be visible in the production enviroment.
This is automatic on the development enviroment.
You need to run this from console:
cd /your/symfony/app
php ./app/console cache:clear --env=prod
Letting the web server build the cache resolved the problem. The command line environment must not be exactly the same as the web server php. On this server it is difficult to actually run command line scripts as the web server user.
Therefore, clearing the cache on the command line with no warmup is the work around:
php ./app/console cache:clear --no-warmup --env=prod

Cannot access Sylius admin or view styled login, register or account pages

I'm looking to use Sylius for a new e-commerce site and wanted to have a play around first as it looks awesome but after installing all seems to work well on the front end but as soon as I view the login or register page, any kind of template or styling is missing. In fact there are no stylesheets or Javascript files set. All that appears are the raw unstyled forms and literally nothing else.
If I try to log in using the credentials at the end of the app/console sylius:install step, I receive the following error:
"An exception has been thrown during the rendering of a template ("None of the chained routers were able to generate route: Route 'cmf_create_put_document_base' not found") in CmfCreateBundle::includejsfiles-create.html.twig at line 17.”
If I complete an order as a new customer and then view my account all I see printed to my screen is who I’m logged in as together with my username and email address and a logout link. That’s it.
Given I’ve had a play with the demo at http://demo.sylius.org/ this is not how I see it working.
If I grep the dev.log file, I find the following errors in addition to the one mentioned above:
[2014-12-11 10:07:29] assetic.ERROR: The template "CmfCreateBundle::includejsfiles-hallo-coffee.html.twig" contains an error: Unable to find file "#CmfCreateBundle/Resources/public/vendor/hallo/src/hallo.coffee". [] []
[2014-12-11 10:07:29] assetic.ERROR: The template "CmfCreateBundle::includejsfiles-ckeditor.html.twig" contains an error: Unable to find file "#CmfCreateBundle/Resources/public/vendor/ckeditor/ckeditor.js". [] []
If I look for the paths #CmfCreateBundle/Resources/public/vendor/hallo/src/hallo.coffee or #CmfCreateBundle/Resources/public/vendor/ckeditor/ckeditor.js I can verify they don’t exist in the vendor/symfony-cmf/create-bundle/Resources/public/vendor/ directory.
Install steps are:
composer create-project -s dev sylius/sylius-standard:v0.11.0 www, also tried composer
create-project -s dev sylius/sylius-standard www
cd www
chmod -R 775 web/media/ app/cache app/logs
chmod 664 app/configs/parameters.yml
composer run-script post-install-cmd as step 1 fails when trying to clear cache
app/console sylius:install with fixtures added
Of note, I’ve tried installing on VMWare (Ubuntu 12.04, PHP5.5) and an Amazon EC2 instance (Ubuntu 14.04, PHP5.6) and while I’m familiar with PHP and ZF2, I have zero Symfony 2 or Sylius experience.
Thanks in advance
I also just experienced this issue. To resolve it, simply add the following line to app/config/routing.yml:
symfony_cmf:
resource: #CmfCreateBundle/Resources/config/routing/rest_no_locale.xml
I'm investigating why the install didn't take care of this.
Although I couldn't get v0.11 working to get to the backend, installing v0.12, which was has just been released has resolved the issue. See more at http://sylius.org/blog/sylius-0-12-0-with-faceted-search.
Did you follow the steps here:
http://symfony.com/doc/current/cmf/bundles/create/introduction.html#installation
I followed #avolkman trick with adding a routing rule:
symfony_cmf:
resource: #CmfCreateBundle/Resources/config/routing/rest_no_locale.xml
But this only fixed problem with missing js files but not fixed problem with missing template on login page.
I'm using new version 0.12 (Sylius Standard) and still have this issue.
To solve the error :
php app/console cmf:create:init-hallo-devel
clear the cache or remove it as usual
php app/console ca:c --env=prod and php app/console ca:c
rebuild assets (you'll see now hallo-coffee.js)
php app/console assetic:dump --env=prod --no-debug
Done ! No more errors

symfony 2, demo not working on remote server

I created fresh symfony 2 app which includes AcmeDemoBundle. It works fine.
I commented out in app_dev.php so that it can be accessed from remote server (openshift cloud). On localhost it works without any problem. I git pushed to openshift, and app_dev.php worked as expected.
Then I moved demo routes to route.yml (for production).
On localhost app.php worked without any problem. So I git pushed to openshift but then app.php threw an error:
failed to open stream Acme/DemoBundle/Resources/views/Welcome/index.html.twig
So, I put back demo routes to routes_dev.yml, git pushed, but openshift error persists.
What might be the problem?
EDIT: The problem is that on my localhost path to twig template is "/var/www/html/jba/php/src/JBA/MainBundle/Resources/views/Default/index.html.twig" but on openshift it still looks to the same directory. But openshift dir layout is different, so it can't find the template. I guess I have to configure openshift to look at right directory. Just don't know how.
Have you cleared the cache for the prod environment?
php app/console cache:clear --env=prod
You might also have a look at the server logs/ the sf2 logs within app/logs/prod.log if this won't help.
I issued the following commands before uploading, but somehow cache seems to be not cleared yet.
php /var/www/html/jba/php/app/console cache:clear --env=prod --no-debug
php /var/www/html/jba/php/app/console cache:clear
Only deleting prod and dev directories under app/cache explicitly helped.
See also
Symfony2: access same route in production as development

Resources