I'm wanting to log certain events to a file. Here is the relevant PHP code:
$logFile = '/var/logs/private/do_not_backup/lms2.0_test_errors.log';
$logMessage = 'New Common Quiz Review about to be created with userQuizId of ' . $userQuizId . '\n\n';
$filePutResult = file_put_contents($logFile, $logMessage, FILE_APPEND);
if (!$filePutResult){
$currentUser = get_current_user();
die ($currentUser . ' could not append ' . $logMessage . ' to log file ' . $logFile . '!');
}
A sample die message would be:
root could not append 'New Common Quiz Review about to be created with userQuizId of 7316553\n\n' to log file /var/logs/private/do_not_backup/lms2.0_test_errors.log!
Here is the ls -l from the log file location:
[userid]@ip-[ip address]:/var/logs/private/do_not_backup$ ls -l
-rw-r--r-- 1 root www-data 0 Nov 22 20:43 lms2.0_test_errors.log
The file is empty as I just created it and am yet to get a successful write to it. Following a die
output, I changed the owner from www-data
to root
, but I left the group as-is.
The PHP page that is quoted-in-part above resides in /var/www/vhosts/[domain]/httpdocs/lms/assessment_review.php
on the same server as the target log file. The server itself is running nginx 1.18.0 with PHP 7.4.3 on Ubuntu Linux 20.04.3.