Reputation: 87
I have a problem. I use this box 'rasmus/php7dev',it works,no problem,But problem so...
system use nginx as default. When I created a directory named 'apix' via vagrantfile. it creates 'apix directory' in /usr/share/nginx/html
sudo touch /usr/share/nginx/html/index.php
run above code on terminal.
<?php
file_put_contents('foo.php',[]);
it does not work..
Warning: file_put_contents(foo.php): failed to open stream: Permission denied in /var/www/default/apix/index.php on line 3
to solve it sudo chmod -R 777 /usr/share/nginx/html/apix
but the result is false!!!!!
what can I do?
Upvotes: 2
Views: 3956
Reputation: 336
If others are getting these kind of errors, you have to make certain that every directory under the /usr/share/nginx/html
directory should have chmod
ed with 777.
You can do this by first cd
to /usr/share/nginx/html
cd /usr/share/nginx/html
Then you have to run:
chmod 777 -R *
Done.
And for the sake of completeness, If you are getting the below error (which is/was my real problem and google took me here wrong) from the /var/log/nginx/error.log
then the commands I mentioned above can help you out.
2017/07/08 16:57:27 [error] 24573#0: *192 FastCGI sent in stderr: "PHP message: PHP Warning: file_put_contents(file): failed to open stream: Permission denied in /usr/share/nginx/html/agentwebsite/index.php on line 106" while reading response header from upstream, client: x.x.x.x, server: example.com, request: "POST /agentwebsite/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "example.com"
Maybe I was wrong. but anyway you can follow the better approach:
You should rather create a user group containing the nginx
and php
users, and set that group as the owner of the directory and then do chmod g+srwx
on those files.
Upvotes: -1
Reputation: 752
If permissions on apix directory is ok, check that you try to write in apix directory. For example, put whole path - file_put_contents('/usr/share/nginx/html/apix/foo.php',[]); May be you just write from wrong dir.
Upvotes: 3