In the development and operation and maintenance process, it is very common to encounter errors. Especially in PHP development, the error troubleshooting process can be difficult because the error message will only be displayed in a small area of the page or recorded in the server log. This article will introduce how to view PHP error logs to facilitate developers to quickly locate and solve problems.
1. Common PHP error scenarios
- PHP code errors
When an error occurs in the PHP code, the system will throw an exception, and PHP will usually The browser outputs an error message. If the logging function is enabled, error information will also be recorded in the error log file. However, this method only works in development environments and not in production environments.
- PHP configuration error
Syntax errors may occur in the PHP configuration file, such as syntax errors caused by missing semicolons, brackets, etc. More serious errors are security issues in configuration files, such as outputting error messages to the browser. These misinformation may be used by attackers to carry out attacks. If a configuration error occurs, you will usually get immediate feedback when accessing the application.
- PHP extension library error
PHP implements many functions in the form of extension libraries, such as database connections, caching, etc. If there are problems installing and using the extension library, it may cause the application to not work correctly. This kind of error usually requires looking at the PHP log files to find exactly where the problem is.
2. The storage location of the PHP error log
The location of the PHP error log depends on the value set in the PHP configuration file (php.ini). The location of PHP error logs, access logs and other logs can be set in the php.ini file.
- PHP error log storage location
PHP error log can be set in the following two ways:
Set log_errors = in the php.ini file On turns on the PHP error log switch.
Set error_log in the php.ini file to specify the storage location of the PHP error log. For example: error_log = "/var/log/php_error.log". When an error occurs, PHP writes the error message to the specified file.
Generally, PHP error logs are stored in the default log directory of the operating system or web server. Common storage paths include:
Default system log path: /var/log/messages or /var/log/syslog;
Apache Web server error log path: /var/log /httpd/error_log;
Ngnix Web server error log path:/var/log/nginx/error.log;
PHP-FPM log default path:/usr/local/php/ var/log/php-fpm.log;
- Access log storage location
The access log records all access records of the application. Access logs can also be enabled and configured by setting access.log and access.format in the php.ini file. For example:
access.log = "/var/log/php_access.log"
access.format = "%h %l %u %t \"%r\" %> s %b \"%{Referer}i\" \"%{User-Agent}i\""
The above settings will specify the storage location and recording method of the access log. When a user accesses the application, access information will be recorded in the specified log file.
3. Check the PHP error log
If an error occurs when accessing the application, these error messages may be written to the PHP error log file. In recent years, in order to improve the security and stability of applications, more and more Web sites have disabled error output. Therefore, if a PHP error occurs, you can try viewing the PHP error log to locate the error message.
PHP error log usually contains a lot of information, such as:
Error type error type.
Message Error message.
File PHP file path.
Line Line number.
Time timestamp.
Among them, the timestamp indicates the time when this error occurred. To view the PHP error log, you can execute the following command in the terminal command line:
tail -f /var/log/php_error.log
The above command will output the last 10 characters of the php_error.log file line and keep the output status so that you can set up to view the error log in real time.
When viewing PHP logs, you can also use scripts to filter. For example, if you only want to find errors related to the "curl" variable in the log, you can use the following command:
cat /var/log/php_error.log | grep curl
This command will Look for "curl" related error messages in the php_error.log file.
4. Conclusion
In PHP application development, error troubleshooting is an essential task. Depending on the error type and error location, choosing an appropriate logging method can help developers effectively locate and solve problems. This article details the storage location of PHP error logs and how to view PHP error logs. These tips will help developers identify and fix bugs more quickly and improve program stability.
The above is the detailed content of How to view php error log. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
