Recording of Logs in linux

Asked

Viewed 62 times

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 did the test on it in windows environment, works perfectly, however when I go to linux, the same stops recording the logs, not even creates the document. You must have some permission to do so?

1 answer

0


When the file cannot be written for reasons of permission php will send a Warning. What may be happening is php is not allowed to write inside the "log" directory. A 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.

  • the permission I have in the directory is this drwxr-Xr-x, in theory it should let me create a new file and edit it not?

  • No, you need to have write permission in the directory, unlike how you sent it only has read and run permission.

  • ah, right, I’ll try here. Thank you

  • That’s right. Thank you!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.