This is the error
RuntimeException: Unable to create the cache directory (1/25/20).
1- Changing the cache directory in the appKernel file didn't fix the problem
/*
public function getCacheDir()
{
return '/mnt/symfony_ram_cache/cache/'.$this->environment;
}
*/
2- Setting the permissions to "chmod 777 -R cache" didn't work, still throws the error
3- App works when I deactivate the twig cache (I obviously need it in production)
#Twig Configuration
twig:
cache: false
4- It DOES create several folders in cache (in both prod and dev) when I empty the cache directoy and reload, so what means the rights are actually set properly
5- Here is a screenshot of the error
6- PS: Updated to symfony 2.5.6 the twig bundle was updated but still have no luck
Maybe you should chown cache directory to user who fires up application (www-data?)?
Edit your
app/config/config.yml
And change this:
From:
twig:
cache: "%kernel.debug%"
To:
twig:
cache: "%kernel.cache_dir%/twig"
I don't know what was wrong, I installed symfony2 from scratch again and now it works.
Related
I write you because I have a problem to run my project Symfony 4 DEV environment. Indeed, I have the impression that this one does not turn correctly because:
when I make a modification it is not visible immediately and I usually have to empty the caches to see them
the profiler and the associated "black bar" do not appear and return a 404 (I have the body tags in my base.htm.twig)
he does not see "immediately" the roads that I created
I installed the profiler via the following command composer require profiler --dev and I am in web server (directly on my NDD and my server).
I also have the variable APP_ENV in dev and it shows me well "dev" when I display it directly in a twig via {{app.environment}}
I hope that my explanations are clear enough and that you will be able to help me. thank you in advance
ps: sorry for my English, but I'm on Google Translate ;)
EDIT : I found the solution with the help of someone on Symfony slack ... I did not install the apache-pack bundle which created a .htaccess file in the public folder and manages the rewrites of url ... that's why my roads were not found.
For my defense, I did not see this bundle anywhere in the documentation
The first you have to install symfony/dotenv (dotenv)
In the .env follow this:
APP_ENV=dev
If you have not install symfony/dotenv
composer require symfony/dotenv
You can read about this here https://symfony.com/doc/current/components/dotenv.html
Also you have to follow config/packages/dev/web_profiler.yaml:
web_profiler:
toolbar: true
intercept_redirects: false
framework:
profiler: { only_exceptions: false }
It's not mandatory added APP_ENV=dev to your .env.
In Symfony 4 you can see in public/index.php this
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
$env = $_SERVER['APP_ENV'] ?? 'dev';
So if you APP_ENV is empty also you environment use is dev, but it's better use APP_ENV in .env
I am unable to successfully run cache clear on my Symfony application. I have set the permissions to the /var/cache directory as 777. But still get this error:
[Symfony\Component\Filesystem\Exception\IOException] Failed to
remove directory "/vagrant/app/var/cache/de~/pools": .
Does anyone know what I am doing wrong here?
This was working before whilst I was using the file sharing type: nfs.
Are you sure you changed the permissions on the cachefolder recursively, and not just one the cache folder itself, (also, try chmod'ing from the host instead of the guest)
EDIT:
if PURELY FOR DEVELOPMENT, setup your vagrant shared folder like so:
config.vm.synced_folder "/home/git/-something-", "/var/www/-something-/public_html", owner: "-something-", group: "nginx", mount_options: ["dmode=777,fmode=777"]
Updated my VM to run the latest version (1.9.5) of vagrant. Was then able to use nfs, see:
config.vm.synced_folder "./", "/vagrant", type: "nfs"
I tried to delete a bundle manually, but an error appeared...
I guess I forgot an essential edition, but I don't know what.
I deleted the file of that bundle, I delete its line in the AppKernel, and I deleted it's lines in the app/routing.yml.
Here is the error :
FileLoaderLoadException in FileLoader.php line 118:
Bundle "DbToYmlBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #DbToYmlBundle/Resources/config/services.yml (which is being imported from "/opt/lampp/htdocs/dublin/app/config/config.yml"). Make sure the "DbToYmlBundle" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#DbToYmlBundle/Resources/config/services.yml" is not empty.
Could someone help to find what is wrong ?
The error message states that the #DbToYmlBundle/Resources/config/services.yml is imported from /opt/lampp/htdocs/dublin/app/config/config.yml
Please check your config.yml's or provide some more information/codes, maybe the output for your prod.log /opt/lampp/htdocs/dublin/app/logs/prod.log
You can try to clear the cache with the console.
For the Dev environment:
php bin/console cache:clear
And for production environment :
php bin/console cache:clear --env=prod
I'm trying to create a /contact route on my website using symfony on windows environment.
I added in the routing.yml file the routes like this:
fstn_venice_homepage:
resource: "#FstnVeniceBundle/Resources/config/routing.yml"
prefix: /
fstn_venice_contact:
pattern: /contact
defaults: { _controller: FstnVeniceBundle:Contact:send }
I have enabled the prod env :$kernel = new AppKernel('prod', true);
Trying to execute the page on prod_env: http://localhost/fstn/web/app_dev.php/contact return an 404 error but in dev_env it displays the contact page correctly.
So that I try to debug the routes by: php app/console router:debug -e=prod
and I get this:
Name Method Scheme Host Path
fstn_venice_homepage ANY ANY ANY /
fstn_venice_contact ANY ANY ANY /contact
I even try to clear the cache by using the Command line :
php .\app\console cache:clear --env=prod --no-debug and it doesn't display any errors but no luck to display contact page on prod environment.
How can I fix this problem?
--edit---
I found the source of my error, actually I should use this path to work in prod env:http://localhost/fstn/web/app.php/contact but I used before http://localhost/fstn/web/contact to test.
Saying the kernel you want a prod environement $kernel = new AppKernel('prod', true); you tell him to forbid access to the dev url http://localhost/fstn/web/app_dev.php/contact.
If you want to access to the prod url, replace app_dev.php with app.php.
You can still let the kernel env configuration to dev, and test in prod environement. After every change, don't forget to clear your cache, and chmod it ;)
Clear your cache, It will be fine.
Cross-posted from the official Symfony Google Group because time is an issue:
I'm in the final push to upload my site to my host. Everything runs fine in the dev environment - no errors, no warnings. When I attempt to access it in prod (localhost/web/app.php/), I get a blank screen. I attempted to clear the cache, to see if that would help, but got the following error:
$ app/console cache:clear --env=prod
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The parameter "kernel.trusted_proxies" must be defined.
I can clear the dev cache without issue.
Please help.
You'll need to add trusted_proxies to your config, even if it is blank.
Within: app/config/config.yml add:
framework:
trusted_proxies: ~
You'll also likely want to delete your cache files (app/cache/prod) and then run your console cache clear ($ app/console cache:clear --env=prod)