Laravel 5.2 could not open laravel.log

I know that there are a lot of questions on this subject, but my problems are really strange, so I decided to publish. 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 fact is that I already made chmod -R 777 storage/ , here is a screenshot:

chmoded

How can I get rid of the error?

+5
source share
6 answers

I finally found a solution. The problem seems to be related to the PSR-4 and auto-import classes

Thus, a solution for anyone else having this problem:

 php artisan clear-compiled composer dump-autoload php artisan optimize php artisan cache:clear 
+2
source

TL; DR;

Run the following commands on the 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 detailed explanation

This usually happens because the web server needs write access to the storage and bootstrap/cache directories.

1. Check which user is using the web server process

First, make sure your web server is running under a restricted account. Nginx and Apache usually automatically create and use the less privileged user and www-data group. You can always use the ps command to check which user is being used by the current service:

 ps aux | grep nginx 

2. Set the owner of the project directory

Then, make sure your Laravel project directory belongs to the same user and group that start the web server process. Suppose your web server is running www-data , and your project directory is in /var/www/laravel , you can set the ownership as follows:

 sudo chown -R www-data:www-data /var/www/laravel 

3. Give write access to the storage and cache directories

This is an IMPORTANT step, make sure that you give write permission to both the storage and bootstrap/cache directories.

 sudo chmod -R 775 /var/www/laravel/storage sudo chmod -R 775 /var/www/laravel/bootstrap/cache 

Does not work?

If the above steps still do not work, you can try running 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 

However, it still does not work?

For the last resource, try setting the resolution to 777 , which means that any users will be able to read and write to the specified directories.

 sudo chmod -R 777 /var/www/laravel/storage sudo chmod -R 777 /var/www/laravel/bootstrap/cache 

I hope for this help.

+31
source

I had the same problem with Centos7 ... I tried EVERYTHING. Finally, I found a stackoverflow post suggesting it could be selinux. I disabled selinux and it will work!

+8
source

U should try something 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.

+5
source

If you are on Centos, disable SELinux enforcement

run the command below to do this.

 setenforce 0 

In my case, this solution worked very well. Hope this helps.

+3
source

use this

chcon -R -t httpd_sys_rw_content_t storage

0
source

Source: https://habr.com/ru/post/1244171/


All Articles