Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The cause and solution of daily Log File Writing failure

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Daily log file write failure reasons and solutions, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Partners who have used Laravel may have encountered the problem of failed writing to daily log files after installing the framework at the beginning. Next, we will explain in detail the reasons for the failed writing of log files and the corresponding solutions.

Before talking about this issue, you may need to briefly introduce the Ownership and Permission of files under the Linux system.

Ownership

User

User is the owner of the file, and by default, the user creates a file whose owner is that user.

Group

A user group can contain multiple users, and all users belonging to this group have the same permissions to access files. Suppose you have a project and many users need access to the project file. you don't need to give these users all permissions manually, you just need to add these users to a group and give these groups access to the file. in this way, only the members of the group can read and write to the file.

Other

Any other user can access the file, so granting permission to the Other user is equivalent to having this right for all users.

Permission

Every file and directory in the UNIX/Linux system has three permissions. Here is a discussion of the three owners.

Read: this permission gives you permission to open and read files. With read access to the directory, you can list its contents.

Write: with read permission, you can modify the contents of the file. With write access to the directory, you can add, remove, and rename files in that directory. Consider a scenario where when you have write access to a file but do not have write access to the file storage directory, you can still modify the contents of the file, but you cannot rename, move, or remove files in the directory.

Execute: in Windows systems, an executable program usually has a .exe suffix, so you can easily run it. In UNIX/Linux, you will not be able to run the program unless you are given executable permissions. If executable permissions are not granted, you can view and modify the program code (granted read and write permissions), but you cannot run it.

Display screenshot of file information under linux

Screenshot of directory information display under linux

The screenshot above shows the information of a file and folder, which we can see:

R stands for readable, w for writable, and x for executable.

The first bit of the file shows -, and the file shows d.

The first picture above, in rw-rw-r--. The first set of rw- indicates that the owner of the file has read, writeable, and non-executable permissions on the file. The second set of rw- indicates that the users in the group to which the file belongs have read, writeable, and non-executable permissions on the file. The third group rmurf-indicates that any other user has readable, non-writable, and non-executable permissions on the file.

Rw-rw-r-- is represented as 664 in binary, and each bit is 1 if you have permission, otherwise it is 0. the first three-bit rw- is expressed in binary as 110and converted into decimal is 6, and so on in the last two groups.

The dior www-data of the first picture above indicates that the owner of the file is the dior user and the file belongs to the www-data group.

We know that in many applications, logs are written to files, and files are named after dates. Therefore, the user who creates the log for the first time is particularly important. If the file is created with the wrong Onwer and Group, other users will fail to trigger writing to the log file.

Let's discuss how many different users might create log files:

The scheduled task performed in Crontab is related to the user who created the Crontab. The file Owner and Group values created at this time are the user and the default Group, respectively.

For some resident background processes, such as queue work in Laravel, the log file Owner and Group values created at this time are the user executing the process and the default Group to which they belong, respectively.

When a normal user visits the log file generated by the website, the Owner and Group of the log file created at this time are both www-data, and the www-data user is the default user of the web server.

From the above analysis, we may have found a solution to the problem.

It is appropriate that the executive user has the right to create log files, which requires a umask of 0002 for the current user.

The default Group for the current execution user should be set to www-data.

Let's talk about my specific solution:

Specify that the www-data user executes crontab:

Sudo crontab-u www-data-e

Modify the permissions to create log files in Laravel:

Edit the confog/logging.php file

Add 'permission' = > 0664

'daily' = > [' driver' = > 'daily',' path' = > storage_path ('logs/laravel.log'),' level' = > 'debug',' days' = > 14, 'permission' = > 0664,], is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report