How can i see php errors in xampp?

Problem:

You run a php script and it displays nothing – just a blank white screen. It happens due to any error occurs in that script. You know changing few things in the php.ini file will display the errors in the browser which will help you to identify the problem quickly.

Solution:

By default, the error reporting is disabled. Hiding error messages, browsers prevent showing any sensitive server information. Though, in the development phase, developers find these error messages helpful to accelerate the development.

To enable error messages, it requires few changes in the php.ini file. Follow the steps below-

Step 1: Locate the php.ini file

  • If you’re using cPanel, find the php.ini file in – /home/username/php.iniHere, username is your cPanel username.
  • If you’re using Plesk for VPS, find the php.ini file in – /var/www/vhost/$domain/etc/php.ini
    Here, $Domain is your domain name.
  • If you’re developing php locally in XAMPP server, the php.ini file is in – /xampp/php/
  • If you don’t have access in the web server, you can ask server guys for it.

Step 2: Enable error displaying option

In the php.ini file, search with “Error handling and logging” string. You’ll see something like the following image-

To enable errors to display in the browser, remove semicolons (;) in front of the following two lines-

; display_errors = On; display_startup_errors = On

The first line will enable displaying errors in the browser and the second line will enable displaying PHP’s startup sequence errors . The previous line can’t handle the startup sequence errors.

So, it will look like the following picture-

Step 3: Decide which errors to display

To display all possible errors, enable one of the following three error reporting  lines in the php.ini file depending on your PHP version.

  • For PHP 5.3 –
    error_reporting = -1
    or error_reporting = E_ALL | E_STRICT
  • For rest of the versions-
    error_reporting = -1
    or
    error_reporting = E_ALL

After enabling the above line in the php.ini file, it will look like the following picture –

Step 4: Enable error log file

To log any errors in the web server’s error log file, uncomment the following line in the php.ini file-

It will look like the following picture-

In the production level, you must turn off the displaying error messages in the browser. But, as the error log file will remain be enabled, any error if ever occurs will be saved in the server’s log file. You can check that file to see error information.

How to find the error log file

You can find the location of your error log file in the php.ini file. Look for a line starting with “error_log = ”. For my local machine the line look like-

error_log = “F:\xampp\php\logs\php_error_log”

There are other methods to accomplish the same task. Check the following-
How to Enable PHP Error Reporting Using .htaccess File?

Introduction

PHP is a server-side scripting language used in web development. As a scripting language, PHP is used to write code (or scripts) to perform tasks. If a script encounters an error, PHP can generate an error to a log file.

In this tutorial, learn how to enable PHP Error Reporting to display all warnings. We also dive into creating an error log file in PHP.

What is a PHP Error?

A PHP error occurs when there is an issue within the PHP code. Even something simple can cause an error, such as using incorrect syntax or forgetting a semicolon, which prompts a notice. Or, the cause may be more complex, such as calling an improper variable, which can lead to a fatal error that crashes your system.

If you do not see errors, you may need to enable error reporting.

To enable error reporting in PHP, edit your PHP code file, and add the following lines:

<?php
error_reporting(E_ALL);
?>

You can also use the ini_set command to enable error reporting:

<?php
ini_set('error_reporting', E_ALL);
?>

Edit php.ini to Enable PHP Error Reporting

If you have set your PHP code to display errors and they are still not visible, you may need to make a change in your php.ini file.

On Linux distributions, the file is usually located in /etc/php.ini folder.

Open php.ini in a text editor.

Then, edit the display_errors line to On.

This is an example of the correction in a text editor:

Edit .htaccess File to turn on Error Reporting

The .htaccess file, which acts as a master configuration file, is usually found in the root or public directory. The dot at the beginning means it’s hidden. If you’re using a file manager, you’ll need to edit the settings to see the hidden files.

Open the .htaccess file for editing, and add the following:

php_flag display_startup_errors on
php_flag display_errors on

If these values are already listed, make sure they’re set to on.

Save the file and exit.

Other Useful Commands

To display only the fatal warning and parse errors, use the following:

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>

You can add any other error types you need. Just separate them with the pipe | symbol.

This list contains all the predefined constants for PHP error types.

One useful feature is the “not” symbol.

To exclude a particular error type from reporting:

<?php
error_reporting(E_ALL & ~E_NOTICE)
?>

In this example, the output displays all errors except for notice errors.

How to Turn Off PHP Error Reporting

To turn off or disable error reporting in PHP, set the value to zero. For example, use the code snippet:

<?php
error_reporting(0);
?>

How to Create an Error Log File in PHP

Error logs are valuable resources when dealing with PHP issues.

To display PHP error logs, edit the .htaccess file by adding the following:

php_value error_log logs/all_errors.log

If you don’t have access to the .htaccess file, you can edit the httpd.conf or apache2.conf file directly.

This log is typically stored in the /var/log/httpd/ or /var/log/apache2/ directory.

To enable error logging, edit your version of the file and add the following:

ErrorLog “/var/log/apache2/website-name-error.log”

You may substitute httpd for apache2 if needed. Likewise, if you’re using nginx, you can use that directory for the error log.

How to Display PHP Errors on a Webpage

Error logs are valuable resources when dealing with PHP issues.

To display PHP error logs, edit the .htaccess file by adding the following:

php_value error_log logs/all_errors.log

If you don’t have access to the file, you can edit the httpd.conf or apache2.conf file directly.

This log is typically stored in the /var/log/httpd/ or /var/log/apache2/ directory.

To enable error logging, edit your version of the file and add the following:

ErrorLog “/var/log/apache2/website-name-error.log”

You may substitute httpd for apache2 if needed. Likewise, if you’re using nginx, you can use that directory for the error log.

Conclusion

This tutorial has provided you with multiple alternatives to enable and show all PHP errors and warnings. By receiving error notifications quickly and accurately, you can improve the ability to troubleshoot PHP issues. If you are implementing new features, installing a new PHP-based app, or trying to locate a bug on your website, it is important to know which PHP version your web server is running before taking any steps.

How do I track PHP errors?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

How do I view php error logs?

Look for the entry Configuration File (php. Find the Error handling and logging section of the php. ini file. Make sure that both display_errors = On, display_startup_errors = On and log_errors = On are present and uncommented. Check the value of error_log - this tells you the location of the file errors are logged to.

How do I fix PHP errors?

Editing the php..
Log into your cPanel..
Go to the File Manager. ... .
Find the “Error handling and logging” section in the php.ini. ... .
Next you can set the display_errors variable to On or Off to either show the errors on your website or not..

How do I turn off error reporting in xampp?

In order to modify the way Xampp shows errors you have to go control panel and open php. ini. Inside this file you can find two points to modify the way it shows errors: “display_errors = On”.