关于apache:尽管具有777权限,php无法打开或写入文件

php can't open or write file despite 777 permisions

我的PHP脚本无法写入文件777权限。
我要写的文件是mash.xml

1
2
3
4
5
6
-rwxrwxrwx. 1 root root   459 May 16  2010 config.xml
-rwxrwxrwx. 1 root root   323 May 16  2010 handler.xml
-rwxrwxrwx. 1 root root 13908 Mar 15 12:18 mash.xml
-rwxrwxrwx. 1 root root   494 May 17  2010 media_audio.xml
-rwxrwxrwx. 1 root root 13967 Feb 15 07:40 media_effect.xml
-rwxrwxrwx. 1 root root   312 May 16  2010 source.xml

我检查了以下问题:
-与文件上传者相同的用户var_dump(get_current_user()); 显示"根"

这是Apache日志:

1
2
3
4
5
[error] [client 155.132.8.52] PHP Warning:  
fopen(/var/www/html/moviemasher_3-1-04/example/save/media/xml/mash.xml):
failed to open stream:
Permission denied in /var/www/html/moviemasher_3-1-04/example/save/media/php/save.php
on line 14

谢谢你的帮助


如果启用了SELinux:

1
semanage fcontext -a -t httpd_sys_rw_content_t"/var/www/html/moviemasher_3-1-04/example/save/media/xml/mash.xml"

随时使用正则表达式作为文件名。


您应该能够像这样编写mash.xml,但我建议您也尝试使用chown更改所有权,例如

chown www-data:www-data mash.xml

(www-data是大多数Linux系统上apache用户的用户组和用户ID)。