search
HomeBackend DevelopmentPHP ProblemHow to enable php error log (steps)

The PHP error log is a file that records errors and warnings that occur when PHP code is running. Turning on PHP error logs allows us to quickly find and solve PHP problems, thereby improving code reliability. In this article, we will introduce how to enable PHP error logging.

1. Check the php.ini file path

First you need to check which php.ini file is used. We can use the following command to view the php.ini file path currently being used.

php --ini

For example:

Configuration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File: /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.2/conf.d/ext-opcache.ini

In the above output information, we can see that the path of the php.ini file currently used by PHP is "/usr/local/etc/php/7.2/php .ini".

2. Modify the php.ini file

Next, we need to modify the php.ini file to enable the PHP error log function.

  1. Open the php.ini file

We can use vim or nano or other similar editors to open the php.ini file.

sudo vim /usr/local/etc/php/7.2/php.ini
  1. Find the error report information

In the php.ini file, we need to find the following code:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

That is, the error reporting level of PHP , if you want to see all error messages, you can change it to the following code:

error_reporting = E_ALL
  1. Enable PHP error log

In the php.ini file, find the following Code:

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on NT, not valid in Windows 95).
;error_log = syslog

Remove the comments and change it to the log file path you want. For example:

error_log = /var/log/php_errors.log

Now that the PHP error log path is set, save the file and close the editor.

3. Restart the PHP service

After completing the php.ini configuration, you need to restart the PHP service to make it take effect. You can run the following command to restart the PHP service.

sudo service php7.2-fpm restart

The above commands are for the php7.2-fpm service. If your version is different, you can use the corresponding version number.

4. Test the PHP error log

Finally, before we write the code, we need to test whether the PHP error log is working properly. Add the following code to your PHP code:

<?php     ini_set(&#39;display_errors&#39;, 1);
    ini_set(&#39;display_startup_errors&#39;, 1);
    error_reporting(E_ALL);

    $var = 1;
    echo $var/0;
?>

This code will throw a warning error when the variable "$var" is divided by 0. Save the code and run it, then open the PHP error log file we set to see if any error messages are output. If so, it means you have successfully enabled the PHP error log.

Summary:

In this article, we introduced how to enable the PHP error log function. First, we need to view the path to the php.ini file currently being used, then edit the file and configure it. After the configuration is completed, we need to restart the PHP service to make it take effect. Finally, we tested whether the PHP error log is working properly. Through this process, we can debug PHP code more conveniently and avoid potential problems.

The above is the detailed content of How to enable php error log (steps). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Implement message queues (RabbitMQ, Redis) in PHP?How to Implement message queues (RabbitMQ, Redis) in PHP?Mar 10, 2025 pm 06:15 PM

This article details implementing message queues in PHP using RabbitMQ and Redis. It compares their architectures (AMQP vs. in-memory), features, and reliability mechanisms (confirmations, transactions, persistence). Best practices for design, error

What Are the Latest PHP Coding Standards and Best Practices?What Are the Latest PHP Coding Standards and Best Practices?Mar 10, 2025 pm 06:16 PM

This article examines current PHP coding standards and best practices, focusing on PSR recommendations (PSR-1, PSR-2, PSR-4, PSR-12). It emphasizes improving code readability and maintainability through consistent styling, meaningful naming, and eff

How Do I Work with PHP Extensions and PECL?How Do I Work with PHP Extensions and PECL?Mar 10, 2025 pm 06:12 PM

This article details installing and troubleshooting PHP extensions, focusing on PECL. It covers installation steps (finding, downloading/compiling, enabling, restarting the server), troubleshooting techniques (checking logs, verifying installation,

How to Use Reflection to Analyze and Manipulate PHP Code?How to Use Reflection to Analyze and Manipulate PHP Code?Mar 10, 2025 pm 06:12 PM

This article explains PHP's Reflection API, enabling runtime inspection and manipulation of classes, methods, and properties. It details common use cases (documentation generation, ORMs, dependency injection) and cautions against performance overhea

PHP 8 JIT (Just-In-Time) Compilation: How it improves performance.PHP 8 JIT (Just-In-Time) Compilation: How it improves performance.Mar 25, 2025 am 10:37 AM

PHP 8's JIT compilation enhances performance by compiling frequently executed code into machine code, benefiting applications with heavy computations and reducing execution times.

How Do I Stay Up-to-Date with the PHP Ecosystem and Community?How Do I Stay Up-to-Date with the PHP Ecosystem and Community?Mar 10, 2025 pm 06:16 PM

This article explores strategies for staying current in the PHP ecosystem. It emphasizes utilizing official channels, community forums, conferences, and open-source contributions. The author highlights best resources for learning new features and a

How to Use Asynchronous Tasks in PHP for Non-Blocking Operations?How to Use Asynchronous Tasks in PHP for Non-Blocking Operations?Mar 10, 2025 pm 04:21 PM

This article explores asynchronous task execution in PHP to enhance web application responsiveness. It details methods like message queues, asynchronous frameworks (ReactPHP, Swoole), and background processes, emphasizing best practices for efficien

How to Use Memory Optimization Techniques in PHP?How to Use Memory Optimization Techniques in PHP?Mar 10, 2025 pm 04:23 PM

This article addresses PHP memory optimization. It details techniques like using appropriate data structures, avoiding unnecessary object creation, and employing efficient algorithms. Common memory leak sources (e.g., unclosed connections, global v

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool