Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
aws ec2上的php文件写入权限被拒绝_Php_Amazon Web Services_Amazon Ec2 - Fatal编程技术网

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

aws ec2上的php文件写入权限被拒绝,php,amazon-web-services,amazon-ec2,Php,Amazon Web Services,Amazon Ec2,我尝试通过php在AWSEC2上编写文件 使用nginx和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 ; I

我尝试通过php在AWSEC2上编写文件

使用nginx和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
文档根目录是

$ ll
total 56
drwxrwxr-x 20 apache apache 4096 Jun 12 06:34 ...
... 
...
我的来源和结果是

我试过了

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

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

警告:文件\u get\u contents/xxx/test.txt:无法打开流:第xx行的/xxx/test.php中没有此类文件或目录

尝试

结果

警告:fopen/xxx/test.txt:无法打开流:第xx行/xxx/test.php中的权限被拒绝


在PHP中,检查文件夹是否可写,如果不可写

if ( ! is_writable($currentPath.'/'.$fileName)){

    echo 'Not writable!!!';
}
然后,通过终端转到ec2,您需要访问,并使用命令

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

看起来您需要修复文件\目录权限我认为Ginx将作为www数据用户运行,因此这些文件需要该用户和/或组可读写。错误消息似乎非常清楚。在第一种情况下,您试图打开一个不存在的文件,而在第二种情况下,您没有正确的文件/文件夹写入权限。aws ec2ami的正确权限是什么?您如何知道操作系统?我键入$sudo chown-R www-data:www-data/xxx/result chown:invalid user:'www-data:www-data'请重试-sudo chown-R www-data/xxx/,似乎是www-data组不存在,只有用户www数据存在。代码结果显示“不可写”,chown显示无效用户“www-data”请重试-sudo chown-R www-data/var/www/html/YOUR-PROJECT-FOLDER
sudo chown -R www-data:www-data /var/www/html/YOUR-PROJECT-FOLDER