Home >Backend Development >PHP Problem >What to do if the php file does not have permissions
Solution to the problem that the php file does not have permissions: 1. Use the "ls -l ./[target_dir]" command to check the permissions; 2. Set the entire directory through "chown -R apache:apache [target_dir]" 3. Execute the "sudo -u apache git reset --hard 977e75b" command.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if the php file does not have permission?
PHP reports file_put_contents failed to open stream: Permission denied in xxxxx on line 2
Use the command to check the permissions: ls -l ./[target_dir]
The permissions of this file have become root, not apache anymore.
Because git is installed in the project, git is executed under the root user. This should be the reason.
Solution:
Set permissions on the entire directory first chown -R apache:apache [target_dir] (restore permissions to apache)
Then every time you execute the git command, use the apache user to execute sudo -u apache git reset --hard 977e75b
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the php file does not have permissions. For more information, please follow other related articles on the PHP Chinese website!