Home  >  Article  >  Backend Development  >  How to solve the problem of writing Laravel.log file

How to solve the problem of writing Laravel.log file

不言
不言Original
2018-07-13 14:41:113159browse

Laravel.log file writing problem

After the project is deployed to the server using the root account, access returns a 500 error.

After a problem occurs, first find the problem according to the following ideas:

  1. View nginx error log

  2. View php error log

  3. Code break point test to see if it can be accessed

No trace found in the error log, 500 errors are usually caused by code errors, confirm whether laravel is opened Debugging function:

# 查看 .env
APP_DEBUG=true

After setting, an error message is displayed on the page: The log file does not have permission to write. This is because the owner and user group of the log file are both root, and the default permission is 755, causing other users other than root to be unable to write.

View the writer

Execute the following command to view the owner of php-fpm:

ps -ef | grep php-fpm

Return information:

apache    9520 11965  0 May25 ?        00:02:11 php-fpm: pool www
apache   10437 11965  0 May26 ?        00:02:10 php-fpm: pool www
root     11965     1  0 May20 ?        00:07:35 php-fpm: master process (/etc/php-fpm.conf)

The first column is php- The execution user of fpm.

Set log permissions

Confirm the permissions of the log directory

ls -l storage/
drwxr-xr-x 3 root root 4096 Jul 11 18:17 app
drwxr-xr-x 6 root root 4096 Jul 12 10:58 framework
drwxr-xr-x 2 root root 4096 Jul 12 16:17 logs

Here you can find that the file owner is root, and php as other users only has read and execute permissions. No write permission.

Modify file permissions

# -R 指递归的修改文件夹和此文件夹下所有内容
# 我的 php 是用户 apache 的,请参考自己的情况修改
chown apache storage/logs -R

The framework folder also has permissions that need to be written. The cache generated by the views layer is in it. You can modify

chown apache storage/framework -R

and above at the same time. That’s the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Laravel development environment deployment homestead installation and configuration process (windows system)

Laravel routing (router) diagram Detailed explanation

The above is the detailed content of How to solve the problem of writing Laravel.log file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn