Keywords: Nginx - AWS - Technical issue - Permissions
Using Lightsail NGINX instance and got a one line in a PHP file that won't do what I need
$s = 'Hello world';
$myfile = file_put_contents('log.txt', $s.PHP_EOL , FILE_APPEND | LOCK_EX);
I want it to create the log.txt file if it's not there. If it is there, I want it to append. It does not do either.
If I create the file, it doesn't work. Only if I chmod the file to 777 via SSH will it work.
However a future piece of work would be to make the file so for reasons beyond the security of 777, this manual approach won't be feasible.
I understand this is down to security settings but really unsure on what to do to make this as secure as I can whilst still giving the PHP access to create/append to a text file
It appears I have a user called www-data. I have tried:
sudo chown -R www-data:www-data html
sudo chmod -R g+s html
Still can't create the file