Recording logs in linux

0

I have the following code in php

<?php
function logs($texto){
    date_default_timezone_set('America/Sao_Paulo');
    $hora = date("H:i:s");
    $data = date("d-m-Y");
    $log = fopen("log/".$data.".txt","a+");
    $escreve = fwrite($log,$hora." - ".$texto. "\r\n");
    fclose($log);
}
?>

I tested it in windows environment, it works perfectly, however when I move to linux, the same thing to save the logs, it does not even create the document. Do you have to have some permission to do so?

    
asked by anonymous 24.04.2018 / 19:03

1 answer

0

When the file can not be written for permission reasons php will send a Warning. What can be happening is that php is not allowed to write inside the "log" directory. One solution would be to use the command:

sudo chmod +777 log

This will cause any user to have full permission in the log directory. Or use the same apache user to create the directory, so he will already have permission to modify the files.

    
24.04.2018 / 20:04