S
S
Sergey Burduzha2017-09-06 20:42:19
ubuntu
Sergey Burduzha, 2017-09-06 20:42:19

How to solve the permissions issue for file_put_contents()?

The site is located in the folder /var/www/test.site/public_html/
Created a function to add content to the file

function writeDataToFile($data){
    
    if(file_put_contents(ORDERS_LOG, $data, FILE_APPEND)){
      return true;
    }
    return false;
  }

ORDERS_LOG - constant - define('ORDERS_LOG', __DIR__.'/../admin/orders.log');
I am getting an error:
Warning: file_put_contents(/var/www/test.site/public_html/eshop/inc/../admin/orders.log): failed to open stream: Permission denied in /var/www/test.site/public_html/eshop/inc/lib.inc.php on line 136

Set owner and owner group to www folder
sudo chown -R serii:serii www
17a6e1696f26410d874f470c11ccb803.pngc1d0857980444ead85f9b24270fd7d9e.png
What else did I forget to do?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2017-09-06
@nazarpc

It is necessary that the web server user has access to all folders along the path to the file, make sure that this is the case, in this case to the var folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question