douju2012 2018-10-30 04:07
浏览 244


I use php5.6 and Apache2.4.6 in centOS7.5
I put a php file in /var/www/html

like this :

echo (__DIR__ . "/test.text");    
file_put_contents(__DIR__ . "/test.text","test text");  

when I access this file through web browser(google chrome), file_put_contents do not function. but,when I execute this file in console, file_put_contents do function. it make test.text file.

Is this problem due to server setting? or some php function doesn't work in access by a browser?

this is httpd/error_log

[Tue Oct 30 13:35:13.191011 2018] [:error] [pid 15037] [client XX.XXX.XX.XXX:29220] PHP Warning:  
file_put_contents(/var/www/html/test.text): failed to open stream: Permission denied in /var/www/html/fpc2.php on line 3

but, this file's permission is 777.

  • 写回答

1条回答 默认 最新

  • doufengsui7449 2018-10-30 04:12

    Right. So it is a permissions problem. You need to make sure that the "user" that runs the php code has permission to write into the directory. I don't know to which user to give the permission, but it may be "web". Try:

    sudo chgrp -R web /var/www/html


    sudo chmod -R g+w *

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥60 PCDN如何使用宽带的电视业务通道拨号叠加带宽?
    • ¥15 遇到这种校园宽带网络应该怎么样解决?
    • ¥30 AXI VIP验证多余打印问题
    • ¥15 利用加权最小二乘法求某品牌手机价格指标,已按照总销量计算出权重,各类型号手机价格已知,如何求得价格指标?
    • ¥15 如何自制一个硬件钱包,有兴趣的朋友一起交流
    • ¥15 (关键词-聊天软件)
    • ¥15 求大家看看这个编程的编法没有思路啊
    • ¥20 WSL打开图形化程序子窗口无法点击
    • ¥15 Jupyter Notebook 数学公式不渲染
    • ¥20 ERR_CACHE_MISS 确认重新提交表单