Home  >  Article  >  Backend Development  >  php cannot write to file

php cannot write to file

王林
王林Original
2019-09-17 13:03:205405browse

php cannot write to file

Environment: Apache/2.4.7 php5

1. Path problem

About the path Question, you can output your own path to see if it is correct. It is recommended to use an absolute path, for example: dirname(__FILE__)."/logs/test.log".

2. Permission issues

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 such that the group and user they belong to 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 writable.

The above content is for reference only!

Recommended tutorial: PHP video tutorial

The above is the detailed content of php cannot write to 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