Nadia S.
—You have errors in your PHP code, but the error message isn’t displaying in the browser. Or maybe you’re debugging your code but you don’t see any error messages in the browser.
Browser error messages probably aren’t showing because of one or more display settings. To fix this, you’ll need to change the error display settings in either the PHP configuration file (php.ini
) or the server configuration file (.htaccess
).
You may not have access to the php.ini
file, in which case you can edit the .htaccess
file.
How you change the php.ini
settings will depend on whether or not you have write access to the php.ini
file.
php.ini
write permissionIf you have write permission to the php.ini
file, check three key parameters in the php.ini
configuration file directly:
error_reporting = E_ALL display_errors = On display_startup_errors = On
On Ubuntu, you can run php --ini
to find the location of the file - likely one or two levels around the etc
folder. If you’re using the XAMPP GUI, you can find it by clicking on “Volumes”, then “Explore”, and locating the etc
folder. If you installed Apache separately, php.ini
is located in the /etc/php/<version>/apache
directory.
php.ini
write permissionIf you don’t have permission to modify php.ini
, you can change the file’s permissions or add the following code to the beginning of the PHP script:
<?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); // rest of the code
Restart the web server for the changes to take effect.
.htaccess
configuration settingsIf you are using Apache, add the following directives to the .htaccess
file:
php_flag display_errors on php_flag display_startup_errors on php_value error_reporting E_ALL
The .htaccess
file is a hidden website configuration file that allows you to make changes to your website without changing the server configuration settings. It’s usually located in your website root directory (where your main index.html
or index.php
file is located).
cd /var/www/html/ sudo nano .htaccess
For security reasons, displaying PHP errors in the browser is not recommended, as this exposes sensitive information. You should rather turn off the error display setting and log errors in another file.
Change the display settings in php.ini
as follows:
display_errors = Off log_errors = On
Locate the log file to view the logged errors:
<?php phpinfo();
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.