Apache: Logging 500 errors from joomla, php and php-fpm

I have a joomla-4.4.8 website with apache 2.4.62 on fedora40 with php-8.3.11 and having some difficulty with logging. This is on my own server, so no cpanel or dashboard. On occasion, I see 500 errors in the apache access logs, but nothing to indicate what caused it or what the specific error was. I’d like to have more detailed information on what caused the 500 error written to a log file.

I’m a Linux admin and not familiar enough with PHP and logging to figure this out. I’d like to modify php.ini to log more information about apache 500 errors, and more specifically those caused by joomla. Here’s what I have so far:

  display_errors = Off
  html_errors = On
  display_startup_errors = On
  log_errors = On
  output_buffering = Off 
  error_reporting = E_ALL
  error_log = /var/log/php_errors.log
  expose_php = Off

These are stored in a 90-php.ini file in /etc/php.d file on fedora40, designed to overwrite any older values that may be different. I’ve also checked them with phpinfo() locally. What is cpanel doing that has it show the line numbers involved in its main error file?

Here’s an example from my apache access log for this domain showing a typical 500 error:

  13.59.58.209 - - [20/Sep/2024:06:40:35 -0400] "GET /advisories HTTP/1.1" 500 481 
  r:"https://example.com/advisories/red-hat" "Mozilla/5.0 AppleWebKit/537.36 (KHTML,
  like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"

Occasionally, we come across a 500 error when browsing the site ourselves, and it does display the error in the browser, but obviously that’s always helpful and also doesn’t always show the line number where the error occurred.

Some PHP errors go to the apache error_log, based on my apache settings. For example:

  [Thu Sep 19 11:00:46.720026 2024] [proxy_fcgi:error] [pid 863110:tid 863147] 
  [client 40.77.167.65:0] AH01071: Got error 'PHP message: PHP Deprecated:  
  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated 
  in /var/www/www.example.com/html/plugins/system/autotweetcontent/autotweetcontent.php on line 86'

I’m also seeing mod_security errors being logged to the apache error_log, as they should. For example:

  [Sun Sep 22 13:05:39.035262 2024] [authz_core:error] [pid 2410993:tid 2411038] 
  [client 143.198.222.185:0] AH01630: client denied by server configuration: 
  /var/www/www.example.com/html/libraries/joomla

The php-fpm log is mostly filled with slow log entries like this:

  [22-Sep-2024 13:16:34] WARNING: [pool example] child 2215306, script 
  '/var/www/www.example.com/html/index.php' (request: "POST /index.php") executing 
  too slow (4.913751 sec), logging

The corresponding slow log for this domain shows the stack trace:

  [22-Sep-2024 13:26:15]  [pool example] pid 2194046
  script_filename = /var/www/www.example.com-443/html/index.php
  [0x00007fd1d9213db0] curl_exec() /var/www/www.example.com/html/plugins/system/cleantalkantispam/lib/Cleantalk/Common/Http/Request.php:216

but there isn’t always a direct enough correlation to the page, particularly when this is the index page, and it doesn’t always exceed the timeout period.

The php_error.log file also rarely shows any useful information.

Step 1: PHP Error Logging Configuration

Your current PHP settings are mostly correct, but let’s ensure they’re optimized for logging:

  1. Update php.ini: Ensure the following settings are in your 90-php.ini file:
ini
display_errors = Off
display_startup_errors = Off
log_errors = On
error_reporting = E_ALL
error_log = /var/log/php_errors.log
    • display_errors should remain Off in production.
  • display_startup_errors can also be Off to avoid showing errors to users.
  • Ensure the path for error_log is writable by the web server user.
  • Check Permissions: Verify that the /var/log/php_errors.log file is writable:
bash
sudo chown apache:apache /var/log/php_errors.log
sudo chmod 664 /var/log/php_errors.log

Restart PHP-FPM: After updating php.ini, restart the PHP-FPM service:

bash
sudo systemctl restart php-fpm

Joomla Configuration

  1. Enable Joomla Debugging:
  • Go to SystemGlobal ConfigurationSystem.
  • Set Debug System to Yes.
  • Set Debug Language to Yes if needed.
  • Set the Log Level to Debug.
  1. Check Joomla Logs: Joomla logs to the logs/ directory. Check logs/joomla.log for any relevant error messages.

Apache Configuration

Ensure Apache Logs Errors: Make sure Apache is set up to log errors properly. In your Apache configuration (likely in your virtual host file), ensure you have:

apache
LogLevel warn
ErrorLog /var/log/httpd/example_error.log