How to enable/display errors in PHP ?

Doing mistakes during development is very common among developers. Sometimes such mistakes results in 500 error or white screen of death (WSOD) in PHP . This usually happens if error reporting is turned off in PHP. The following guide will help you display errors in your php code.

Why to enable error reporting in PHP ?

Mistakes are very common trend among programmers. During the debugging, the errors are very helpful. Errors can help developers find the exact issue and helps them to resolve it quickly. By default, the error reporting is disabled in php.ini for security reasons. Therefore, it is recommended to enable error reporting only on development environment.

How to display errors in PHP without php.ini ?

The most simplest and quickest method to display all errors in is to add following lines to your PHP code file –

The above method overrides php.ini file configuration. This method can be used if you’re not having access to php.ini file such as in case of shared servers.

How to enable error reporting in php using php.ini file ?

In this method you need to add these lines to every php file where you want to display errors. To avoid such conditions, we can enable error reporting in PHP globally. This can be achieved using php.ini file.

What is php.ini file ?

During the php installation, php.ini is a default configuration file provided. This is a very important file and contains all the configurations related to php. Each time the php is executed, the php.ini is read by the system.

Where is php.ini file located on server ?

The php.ini can be found on different locations based on your server, php version etc. The below two methods can help you find the location of your php.ini file in your server.

Method 1 – Using phpinfo() function

In this method, create a php file in our server and add the following lines to it –

Now in your browser, execute the above file. You’ll see something like the screenshot below. The marked area represents the location of your php.ini configuration file –

Display errors in php

Configuring php.ini to enable error reporting and display errors in php

In your php.ini configuration file, find and update the following variables –
error_reporting = E_ALL
display_errors = On

Now save the file and restart your server, this will enable error reporting in your php server.

Also Check – Install phpmyadmin in ubuntu

Reference – error_reporting()

Author: Deepak Kumar

This is Deepak Kumar, founder of True Infosystems and of-course the chief content creator at Started my carrier as a Freelancer and now a top-rated Freelancer at Upwork, delivered over 200 successful projects with highly positive user ratings and counting.

Leave a Reply

Your email address will not be published. Required fields are marked *