I'm using LEMP stack (PHP 7) on ubuntu 16.10, and after cleaning Symfony 3 cach php bin/console cache:clear I'm getting error after refreshing site:
RuntimeException in ClassCollectionLoader.php line 248:
Failed to write cache file "/var/www/html/mywebsite/var/cache/dev/classes.php".
and every time I have to do chmod 777 commands manually to make it work again.
So what I have to do not to make chmod's after cleaning cache each time, are there any solutions to to it once?
Related
I have a simple project in Symfony 5.2 and I wanted to install composer mailer for user registration, so I ran:
composer require symfony/mailer
But when it was executing cache:clear, it returned an error and suddenly I could do nothing in my project, maker-bundle is not working and if I run server it throws an error:
In App_KernelDevDebugContainer.php line 429:
Warning: require(C:\Users\Javi\Dropbox\DAW\GeoSport\var\cache\dev\ContainerTtp0Lx5\getVarDumper_ContextualizedCliDumper_InnerService.php): failed to open stream: No such file or directory
list [--raw] [--format FORMAT] [--] [<namespace>]
Error when I run symfony server:start:
Once in a while you will get that error.
Something went wrong during your cache clear and the cache is out of sync. Some cache files are still there and refer to already removed cache files.
Best is to manually clear your cache folder
This has turned out to be the best solution over the years for me.
So basically it is manually clearing the cache folders yourself via command line
# For Mac: -r means "recursively" and -f means "forced"
rm -rf route/to/var/cache
# For Windows: /s means "include subdirectories" /q means "forced without asking"
rmdir /s/q route/to/var/cache
And watch out with that command. It is dangerous. When accidentally pressing enter when you are still typing the folders, you can have serious damage 😅. So maybe type the route/to/var/cache first and then go prefix it with the command.
Cleaning out the cache folder manually is actually almost the same as doing a cache clear without warmup. Info here
I am deploying a Symfony 4.4 app to AWS ElasticBeanstalk and noticed that the cache wasn't cleared after each deploy.
The app was running fine though, exception made to the stale cache.
To resolve the cache issue I added the following file:
/.ebextensions/deploy.config
container_commands:
01-clear-cache:
command: php bin/console cache:clear --no-warmup --env=prod
That seems to clear the cache but then somehow it changes permissions so that I then get the error when trying to access the app.
Fatal error: Uncaught RuntimeException: Unable to write in the cache directory (/var/app/current/var/cache/prod)
Why does running cache:clear changes permissions and is there a way to avoid that happening, or at least how to resolve afterwards, ie, in the same/another .ebextensions file?
These commands are run by the root user, as specified in the docs.
The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server. Any changes you make to your source code in the staging directory with a container command will be included when the source is deployed to its final location.
(Emphasis mine).
When re-creating the cache, the new directories are owned by root, and your PHP process can't write there if it needs to.
Execute your command so it runs using the same user than your PHP runtime. E.g. if it runs under the www-data user:
container_commands:
01-clear-cache:
command: sudo -u webapp php bin/console cache:clear --no-warmup --env=prod
When using Ansible you can actually just use become: true as a mechanism to become a root user and become_user: xxx to become the desired user.
Example:
---
# roles/app/tasks/main.yml
- name: Run composer install
become: true
become_user: ubuntu
composer:
command: install
working_dir: "{{ deploy_path }}"
Note that you have to define a variable called deploy_path.
I've recently upgraded Symfony to the new Symfony4.1. As seen over here we no longer need to setup file permissions anymore. I ran the command:
php bin/console cache:warmup
And no errors came while running that. However when I try and view the website. I get the following error.
Uncaught RuntimeException: Unable to write in the cache directory (/var/www/mywebsite.com/var/cache/prod)\n in /var/www/mywebsite.com/var/bootstrap.php.cache
Obviously this means that the new feature of Symfony4.1 is not working for me. Any idea what might be causing this?
Give permissions to cache directory with bash command:
sudo chmod -R a+rw /path/to/cache_directory/
I use laravel on homestead. I tried a lot of different commands in order to clear cache and other stuff and nothing helped.
I keep getting this error:
file_put_contents(/Users/Victor/Sites/pft/pft-back/storage/framework/cache/data/05/9f/059f793d8b638b8c21ead7edbba382b9e9183fac): failed to open stream: No such file or directory
What I've tried is:
Set 777 for storage folder
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
No idea why it's happening but I'm pretty sure because of homestead since I've just recently started using it.
Also I tried all commands both from homestead user and mac user (I'm running homestead on mac)
The problem is the underlying storage maps, could check if storage/framework, storage/framework/cache and storage/framework/cache/data have r/w permission and otherwise create them?
I am getting started with Laravel 5, using Homestead/Vagrant for a server, SSHing in with Putty.
I'm building my first site and it's not creating a log in /storage/logs. Neither is it displaying errors. I've run chmod -777 on the /storage directory, so that's not it. Any ideas?
UPDATE: as suggested, I went into the error.log in vagrant/var/hhvm/. Sure enough, that was it. The error was "\nFatal error: Class undefined: HTML in /home/vagrant/Code/Laravel/storage/framework/views/441aef21be6c3c32079f86e5812a9d0a on line 39".
I followed the steps listed below to add the class. http://laravelcollective.com/docs/5.0/html#installation Edited the composer.json, ran composer update, added the provider and aliases. Still getting the white screen of death.
There is now a log in /storage/, which says:
[2015-05-27 11:33:44] local.ERROR: exception 'InvalidArgumentException' with message 'Command "tail" is not defined.' in /home/vagrant/Code/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php:549 , followed by a stack trace. This seems to be the error thrown by my attempt to run laravel tail, which I did before looking in the vagrant log. Nothing in there about why it's not loading now.
As FBidu answered very good answer,but artisan tail is not come with default package in laravel 5. However can be installed with
composer require spatie/laravel-tail
In config/app.php
'providers' => [
...
'Spatie\Tail\TailServiceProvider',
...
];
After that’s done you can tail your local log with
php artisan tail
The remote log can be tailed with
php artisan tail production
Link here
First of all, you have to do an chmod -R 777 on storage to guarantee that all of the files and folders within storage are writeable.
Secondly, it would be nice to allow the debug mode!
You can also try to run artisan tail to get the latest logs