doudao5287 2018-06-12 06:23
浏览 200

aws ec2上的php文件写入权限被拒绝

i tried write file on aws ec2 via php.

use nginx and php-fpm.

nginx www.conf

$ vi /etc/php-fpm-7.0.d/www.conf 

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

document root is...

$ ll
total 56
drwxrwxr-x 20 apache apache 4096 Jun 12 06:34 ...
... 
...

my sources and results is...

i tried

$fileName = 'test.txt';
$contents = 'hello ';
$currentPath = dirname(__FILE__);

$fgc = file_get_contents($currentPath.'/'.$fileName);
file_put_contents($contents, $fgc);

result

Warning: file_get_contents(/xxx/test.txt): failed to open stream: No such file or directory in /xxx/test.php on line xx

tried

$fp = fopen($currentPath.'/'.$fileName, "w");
fwrite($fp, $contents);
fclose($fp);

result

Warning: fopen(/xxx/test.txt): failed to open stream: Permission denied in /xxx/test.php on line xx

  • 写回答

1条回答 默认 最新

  • duanqun9740 2018-06-12 06:31
    关注

    In PHP, check if folder is writable, if not,

    if ( ! is_writable($currentPath.'/'.$fileName)){
    
        echo 'Not writable!!!';
    }
    

    Then, go to ec2 via terminal, you need access, and use command

    sudo chown -R www-data:www-data /var/www/html/YOUR-PROJECT-FOLDER
    
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型