Table of Contents
Introduction
This is going to be a quick one. If you’ve ever tried to visit a site on your server running Openlitespeed or Litespeed (not 100% confirmed, you might get the following output.
Error: can't open log file!
Cause? Can’t Write to Log File
It’s actually pretty straight forward, Openlitespeed and Litespeed can’t write to a log file. It’s strange that it’s returning a 200 error, when it should be returning a 500 error.
But what log file? Check the main Openlitespeed / Litespeed log /usr/local/lsws/logs/error.log
for errors
# tail -f /usr/local/lsws/logs/error.log 2024-08-18 09:24:20.796796 [NOTICE] [1865589] [127.0.0.1:23046:HTTP2-1#domain.com] [STDERR] PHP Warning: fopen(/var/www/domain.com/logs/7g.log): Failed to open stream: Permission denied in /var/www/domain.com/htdocs/7g-gridpane.php on line 129
You’ll see above that this error is related to the 7G log file from GridPane.
Fixing Log File Permissions (GridPane 7g.log)
If you’re GridPane and this is related to the 7g.log file. Then you can do the following to fix the issue.
The log file /var/www/domain.com/logs/7g.log
will unfortunately become owned by root:root, and you will need to change the ownership to the system user for the site.
chown user:user /var/www/domain.com/logs/7g.log
To find the user, check the GridPane UI and under Site’s it should list the system user. Here’s
Why is this occurring?
I don’t know why this is happening, but it might be due to log rotation or some other mechanism. Reach out to GridPane support.
When the 7G is triggered on a requests, the PHP file /var/www/domain.com/htdocs/7g-gridpane.php
is fired. This then writes to the appropriate log file /var/www/domain.com/logs/7g.log
The code needs to be updated to send a 500 error. Specifically the function perishablePress_7G_log
here’s the updated code.
function perishablePress_7G_log() { list ($date, $method, $protocol, $uri, $string, $address, $host, $referrer, $agent) = perishablePress_7G_vars(); $log = $address .' - '. $date .' - '. $method .' - '. $protocol .' - '. $uri .' - '. $string .' - '. $host .' - '. $referrer .' - '. $agent ."\n"; $log = preg_replace('/(\ )+/', ' ', $log); // Attempt to open the log file and write to it $fp = @fopen(SEVENGLOGFILE, 'a+'); if ($fp) { fwrite($fp, $log); fclose($fp); } else { // Log the error to the PHP error log error_log("Error: can't open log file at " . SEVENGLOGFILE); // Send a 500 status code header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); exit("Error: can't open log file!"); } }