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?
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
directories This 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 are in Centos, then disable SELinux enforcement
run below command to do this.
setenforce 0
In my case, this solution worked very well. Hope this will help.
U should try somethings like this-
php artisan cache:clear
php artisan clear-compiled
sudo chmod -R 777 storage/ -R
composer dump-autoload
U can go to this question for more details.
I finally found a solution.. Seems like the problem had to do with PSR-4 and auto importing classes
So here's the solution for anyone else having this problem:
php artisan clear-compiled
composer dump-autoload
php artisan optimize
php artisan cache:clear
use this
chcon -R -t httpd_sys_rw_content_t storage
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.