Error logs in Bitrix are essential for diagnosing issues such as server misconfigurations, PHP errors, or database-related problems. Understanding how to access and interpret these logs can help resolve issues faster.

Locating the Bitrix Error Log

Bitrix-Specific Log Files

Bitrix has a built-in logging system. The logs can be found in:

/bitrix/php_interface/after_connect.php
/bitrix/modules/logs/

Web Server Log Files

Depending on your web server configuration:

  • Apache logs:
  • /var/log/apache2/error.log
  • Nginx logs:
  • /var/log/nginx/error.log
  • PHP-FPM logs:
  • /var/log/php7.x-fpm.log

Custom Error Log for Bitrix

If you have configured Bitrix to write custom logs, check the file path set in the code:

define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/bitrix/log.txt");

Log entries are saved in:

/bitrix/log.txt

Enabling Error Logging in Bitrix

Enable PHP Error Logging

  1. Open your php.ini file:
    sudo nano /etc/php/7.x/apache2/php.ini
  2. Enable logging and set the log file:
    log_errors = On
    error_log = /var/log/php_errors.log
  3. Restart the web server:
    sudo systemctl restart apache2

Enable Bitrix Debugging

Edit the dbconn.php file in your Bitrix installation:

define("DEBUG_MODE", true); // Enable debugging
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/bitrix/log.txt"); // Custom log file

Checking Common Errors in Bitrix Logs

Error Type Typical Error Fix
Database Connection Errors [DB Connection Error]: Unable to connect to the database
  • Verify database credentials in dbconn.php.
  • Check the MySQL service status:
  • sudo systemctl status mysql
PHP Errors PHP Fatal error: Uncaught Error: Call to undefined function
  • Ensure all required PHP modules are installed (e.g., php-mysql, php-gd).
  • Install missing modules:
  • sudo apt install php-mysql php-gd
Module Loading Errors Error: Unable to load module /bitrix/modules/some_module
  • Check if the module directory exists.
  • Reinstall the module if necessary.

Analyzing and Filtering Logs

Search for Specific Errors

Use grep to filter relevant log entries:

grep "ERROR" /bitrix/log.txt

Monitor Logs in Real-Time

Use tail to monitor logs as issues occur:

tail -f /bitrix/log.txt

Clearing Old Logs

Large log files can consume disk space and slow down the server.

  • Check the size of log files:
  • du -sh /bitrix/log.txt
  • Clear log files:
  • > /bitrix/log.txt

Best Practices for Bitrix Error Logging

  1. Rotate Logs Automatically:
    • Use logrotate to manage large log files:
    • sudo nano /etc/logrotate.d/bitrix
    • Example configuration:
    /var/www/bitrix/log.txt {
        daily
        rotate 7
        compress
        missingok
        notifempty
    }
  2. Set Appropriate Log Levels:
    • Only enable detailed logging for troubleshooting.
    • Disable detailed logs in production to improve performance.
  3. Secure Log Files:
    • Restrict permissions:
    • chmod 600 /bitrix/log.txt
  • Locate and enable logs in /bitrix/log.txt or /var/log/.
  • Use error logs to debug database, PHP, or server-related issues.
  • Regularly clean and rotate logs to optimize performance.