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.
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
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-
|; log_errors = On|
It will look like the following picture-
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?