php can't open or write file despite 777 permisions

坚强是说给别人听的谎言 提交于 2019-12-25 01:55:11

问题


My php script is unable to write a file despide 777 permission. the file i want to write is mash.xml

-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

i checked the following issue : - same user as file uploader, var_dump(get_current_user()); displays "root"

this is apache log :

[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

thanks for your help


回答1:


If SELinux is enabled:

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

Feel free to use a regex for the filename.




回答2:


You should be able to write mash.xml like this, but I suggest you also try chown to change the ownership, eg

chown www-data:www-data mash.xml

(www-data is the user group and user id of the apache user on most linux systems).



来源:https://stackoverflow.com/questions/5417610/php-cant-open-or-write-file-despite-777-permisions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!