Symfony cache:clear error ruined my whole project - php

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

Related

Symfony on AWS EB - Unable to write in the cache directory after cache clear

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.

Symfony 4.1 cache not being created

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/

After cleaning symfony3 cache I get permission error

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?

New Laravel Project Throwing 500 Error: require(): Failed opening required autoload.php

I trying to learn laravel and I am attempting to set it up on my server.
I have meticulously followed all the instructions in this tutorial while changing some variables based on the names of my own directories:
http://davidmyers.name/post/laravel-on-digital-ocean
The 500 error only is thrown when I visit the laravel project's public folder. When I attempt to visit any other page such as PHPMyAdmin or any other PHP or HTML page, the page pulls up just fine.
Is there anything I could be missing that is not included in the tutorial that I referenced? I double checked that I am following all the steps correctly.
Also, running composer update in the directory throws this error:
[RuntimeException]
Error Output: PHP Warning: require(/var/www/html/testproj/bootstrap/../vendor/autoload.php): failed to open stream: No
such file or directory in /var/www/html/testproj/bootstrap/autoload.php on line 17
PHP Fatal error: require(): Failed opening required '/var/www/html/testproj/bootstrap/../vendor/autoload.php' (include
_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/testproj/bootstrap/autoload.php on line 17
I found this related stackoverflow article:
Laravel 5 Failed opening required bootstrap/../vendor/autoload.php
but the solution did not work for me, since my phpinfo() shows that OpenSSL is enabled.
The problem is that the server does not have access to those locations.
Run the following commands
sudo chmod 755 -R "your project name"
and then
chmod -R o+w "your project name" /storage
if it still doesn't work try running:
sudo chmod 775-R "your project name"
sudo chmod 775-R "your project name"/storage
or
sudo chmod 777-R "your project name"
sudo chmod 777-R "your project name"/storage
Have you run composer install ? This should automatically run php artisan optimize after install, which I believe is the command to create the file in question.
You must install dependencies by composer using:
composer install
and then give right permission to storage directory:
chmod 777 -R storage
or
sudo chmod 777 -R storage
It turns out that I was doing everything right, but when I went to run composer install I didn't see that it was throwing an installation error due to my server not having enough memory. Increasing my server's memory fixed the problem.
There are 2 things to consider,
1. Web server throwing 500 error (as if text and font were from Chrome) or
2. The application is showing 500 error (with beautiful image and text)
Case 1: you probably need to install composer
sudo composer install
Case 2: Check appropriate permission on storage/ (as suggested on other answers) and check if you have .env file. if not copy .env.example and rename to .env and you also need to generate application key.
sudo php artisan key:generate
PS: You may be in this situation mostly if you have used git to deploy your code on server and your development machine is different. This answer is based on the scenario which I faced and how it was solved.

Clone Laravel 4 Project - Permission Problems

I cloned a project on my local machine and used it as a starting point for another project. I've been plagued by permission problems ever since.
Whenever I clear the cache, I notice that nothing happens. I get no error, but the cache doesn't in fact clear. Trying to manually delete the files is not allowed. Trying to change permissions on the files is not allowed.
$ chmod -R 777 app/storage
chmod: Unable to change file mode on app/storage/cache/14: Operation not permitted
The only thing that works is using sudo:
$ sudo chmod -R 777 app/storage
$ php artisan cache:clear
And this will only work for a single page load. All future attempts to clear that cache fail silently and again require the above procedure.
How can I fix this issue and get the permissions working properly again?
SOLUTION:
I made a change to my local Apache settings following this procedure:
http://paulmason.name/item/change-apache-user-group-in-lion-os-x
A final sudo chmod got me up and running.

Categories