Current Location: Home> Latest Articles> Complete Guide to Viewing PHP Error Logs on Linux Systems

Complete Guide to Viewing PHP Error Logs on Linux Systems

gitbox 2025-07-20

How to View PHP Logs on Linux

Being able to view PHP logs on a Linux system is an essential skill for every developer and system administrator. Proper log management helps in identifying issues quickly and improves development and maintenance efficiency. This guide explains PHP log types, how to locate them, commands to view log content, and how to configure PHP logging through php.ini.

Types of PHP Logs

Understanding the different types of PHP logs helps with efficient troubleshooting. Common log types include:

  • Runtime error messages
  • Debug output
  • Warnings and notices

These are usually stored in designated log files for review and analysis.

How to Find PHP Log File Location

The location of the PHP error log is defined in the php.ini configuration file. Use the following command to find where your logs are being saved:

php -i | grep error_log

It will output something like:

error_log => /var/log/php_errors.log

This indicates that PHP errors are logged to /var/log/php_errors.log. The path may differ depending on your server setup.

Common Linux Commands to View PHP Logs

Once you’ve identified the log file path, you can use various Linux commands to view its contents.

Using the cat Command to View Entire Log

The most straightforward way to read the full log file is with the cat command:

cat /var/log/php_errors.log

This displays the entire content of the file, which is fine for small logs.

Using the tail Command to View Recent Entries

To only check recent log entries, use the tail command:

tail -n 50 /var/log/php_errors.log

This shows the last 50 lines of the log file—useful for quick diagnostics.

Using the grep Command to Filter Log Entries

To locate specific errors or keywords in the log, use the grep command like so:

grep "specific error" /var/log/php_errors.log

This filters the log and shows only lines containing the keyword or error string.

Configuring PHP Error Logs

You can control PHP logging behavior by editing the php.ini file. Set the following parameters:

log_errors = On
error_log = /var/log/php_errors.log

log_errors enables error logging, and error_log specifies the output path. Be sure to restart your web server after making changes.

Conclusion

Knowing how to access and interpret PHP logs is crucial for maintaining and debugging applications. From identifying the log types and locating log files to using Linux commands effectively, proper logging practices can significantly streamline development workflows. Hopefully, this article has provided valuable insight into managing PHP logs on Linux systems.