When I try write logs from this part of code:
function _log_write($message) {
$trace = debug_backtrace();
$function_name = isset($trace[2]) ? $trace[2]['function'] : '-';
$mark = date("H:i:s") . ' [' . $function_name . ']';
$log_name = BOT_LOGS_DIRECTORY.'/log_' . date("j.n.Y") . '.txt';
file_put_contents($log_name, $mark . " : " . $message . "\n", FILE_APPEND);
}
I caught this exception:
PHP message: PHP Warning: file_put_contents(/var/www/php/logs/log_30.11.2022.txt): failed to open stream: Permission denied in /var/www/php/global.php on line 24
This is my permissions for current dirs:
-rwxr-xr-x 1 ubuntu www-data 925 Nov 25 09:49 config.php
-rwxr-xr-x 1 root root 618 Nov 30 18:07 global.php
-rw-r--r-- 1 root root 2748 Nov 30 18:10 index.php
drwxr-xr-x 2 ubuntu www-data 4096 Nov 19 15:39 logs
Also here some settings from /etc/php/7.4/pool.d/www.conf
file:
user = www-data
group = www-data
I want to write logs from php script on linux, but I cath Permission denied
-exception.