# Display PHP Errors in the Browser for Debugging

> Enable PHP error display by setting display_errors and error_reporting in php.ini, using ini_set() in your script, or adding directives to .htaccess

**URL:** https://sentry.io/answers/how-do-i-get-php-errors-to-display/

---

## The Problem

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.

## The Solution

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.

### Change the php.ini configuration settings

How you change the `php.ini` settings will depend on whether or not you have write access to the `php.ini` file.

#### With `php.ini` write permission

If you have write permission to the `php.ini` file, check three key parameters in the `php.ini` configuration file directly:

```bash
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.

#### Without `php.ini` write permission

If 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
<?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.

### Change the `.htaccess` configuration settings

If you are using Apache, add the following directives to the `.htaccess` file:

```bash
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). 

```bash
cd /var/www/html/
sudo nano .htaccess
```

### View PHP errors in production

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:

```bash
display_errors = Off
log_errors = On
```

Locate the log file to view the logged errors:

```php
<?php
phpinfo();
```

---

*Source: [sentry.io/answers/how-do-i-get-php-errors-to-display/](https://sentry.io/answers/how-do-i-get-php-errors-to-display/)*
