I know there are a lot of questions on this topic but my issues is really weird that's why I decided to post.
I have this error in /var/logs/apache/error.log
[Tue Mar 01 07:26:51.435312 2016] [:error] [pid 8837] [client 127.0.0.1:37843] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/personale/librarie-cor/storage/logs/laravel.log" could not be opened:
failed to open stream: Permission denied' in /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\nStack trace:
\n#0 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)
\n#1 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Logger.php(289): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)
\n#2 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Logger.php(565): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)
\n#3 /var/www/personale/librarie-cor/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)
\n#4 /var/www/personale/librarie-cor in /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87
The thing is I already did chmod -R 777 storage/
, here is a screenshot:
How can I get rid of the error?
Change all file permissions to 644. Change all folder permissions to 755. For storage and bootstrap cache (special folders used by laravel for creating and executing files, not available from outside) set permission to 777, for anything inside.
If you encountered an error that says “Could Not Be Opened In Append Mode: Failed To Open Stream: Permission Denied” such us the the image below, you can solve this by simply changing the permission access of certain file. The chmod 666 will allow all users to read and write but cannot execute the file.
There is very easy way to clear log with php artisan log:clear command using Laravel More Command Package. The above will deleted all old log data from /storage/logs/ directory.
TLDR;
Run the following commands on your terminal
# Clear Laravel cache and the compiled classes
php artisan cache:clear
php artisan clear-compiled
# Change the storage and cache directories permission
sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache
# Regenerate the composer autoload file
composer dump-autoload
More thorough explanation
This usually happens because of the web server needs a write access to the storage
and bootstrap/cache
directories.
First, make sure that your webserver process is run by an account with limited privileges. Nginx and Apache usually will automatically create and use the less privileged www-data
user and group. You can always use the ps
command to check which user is being used by the running service:
ps aux | grep nginx
Next, make sure that your Laravel project directory is owned by the same user and group who run the web server process. Suppose your web server is run by www-data
and your project directory is located at /var/www/laravel
, you can set the ownership like so:
sudo chown -R www-data:www-data /var/www/laravel
storage
and cache
directoriesThis is the IMPORTANT step, make sure you give the write permission both to storage
and bootstrap/cache
directories.
sudo chmod -R 775 /var/www/laravel/storage
sudo chmod -R 775 /var/www/laravel/bootstrap/cache
If the above steps are still not working, you can try to run the following commands in the shell:
# 1. Clear Laravel cache
php artisan cache:clear
# 2. Delete the compiled class
php artisan clear-compiled
# 3. Regenerate the composer autoload file
composer dump-autoload
For the last resource, try to set the permission to 777
which means any users will have the ability to read and write to the given directories.
sudo chmod -R 777 /var/www/laravel/storage
sudo chmod -R 777 /var/www/laravel/bootstrap/cache
Hope this help.
I had the same issue with Centos7 ... I tried EVERYTHING. Finally, I found a post on stackoverflow suggesting it could be selinux. I disabled selinux and it worked!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With