Score:0

"Failed to open stream: Permission denied" Lighttpd on Ubuntu (VM Ware)

tw flag

The situation is, I have written some code in PHP to write JSON file in the server(Lighttpd) the code is

'''<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    function get_data() {
        $datae = array();
        $datae[] = array(
            'Name' => $_POST['name'],
            'Branch' => $_POST['branch'],
            'Country' => $_POST['country'],
        );
        return json_encode($datae);
    }
    
    $name = "gfg";
    $file_name = $name . '.json';

    if(file_put_contents(
        "$file_name", get_data())) {
            echo $file_name .' file created';
            echo "<br><br><br><br><a href='get.html'>view data</a>";
        }
    else {
        echo 'There is some error';
    }
}

?> '''

this same code works fine with Apache servers. I have giver permissions as 777 to www folder

the error log of Lighttpd is 2022-10-13 09:50:13: (mod_fastcgi.c.451) FastCGI-stderr:PHP Warning: file_put_contents(gfg.json): Failed to open stream: Permission denied in /var/www/html/web/www/pc/a/gfg.php on line 18

any help will be appreciated

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.