Home  >  Article  >  Backend Development  >  What should I do if php cannot write files?

What should I do if php cannot write files?

藏色散人
藏色散人Original
2021-06-15 09:27:242273browse

Solution to the problem that php cannot write files: 1. Use an absolute path, such as "dirname(__FILE__)."/logs/test.log""; 2. Use the chmod command to change other permissions of the file to Writable.

What should I do if php cannot write files?

The operating environment of this article: linux5.9.8 system, php5 version, DELL G3 computer

What should I do if php cannot write files?

Solution to the problem that php cannot create or write files under Linux

Environment Apache/2.4.7 php5

There are only two reasons for file writing errors: path problems or Permissions issue.

Regarding the path problem, you can output your own path to see if it is correct. It is recommended to use an absolute path, such as dirname(__FILE__)."/logs/test.log".

There are many possibilities for permission issues. I will only talk about my own problems here. Since I create the file first, I must set other permissions of the folder where the created file belongs to be writable, that is, the rightmost w in drwxrwxrwx is required. The default permissions of the files created at this time are as follows

The group and user to which they belong are www-data, and the permissions are 644.

Another reason may be that the file you created through the command line cannot be written. For example, the current user is root and I created a file through the command line. The default permissions of the file are not writable by other users. The solution is to use the chmod command to change the other permissions of the file to be writable.

Recommended Study: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot write files?. 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