60

I'm new to PHP and the whole LAMP stack but I've managed to get it up and running on my Ubuntu 10.10 system. Everything seems to be working with the exception of error reposting in the browser which I just can't seem to get working (and which I can't work without!).

I've read a number of article and other threads which indicate that the following values should be applied in the file /etc/php5/apache2/php.ini:

  • display_errors = On
  • display_startup_errors = On

I've restarted apache2 and even restarted my computer but for the life of me I just can't get it working. I've even tried using phpinfo() function which reports that these settings are as I've set them so I know it's picking up the correct configuration file but nothing!

Any help would be welcome.

JLove
  • 1,491
  • 1
  • 16
  • 37
  • What does phpinfo() say about Local value of these settings? What is error_reporting value? How do you check for errors? – Your Common Sense Feb 19 '11 at 12:09
  • Are you expecting an error or otherwise forcing an error to occur so that you can test this? If so, how are you doing this? Also, what is the exact version of PHP you are running? Be sure to restart apache every time you change a config in PHP. (Restarting the machine is not necessary.) – bogeymin Feb 19 '11 at 12:15
  • possible duplicate of [PHP doesn't show any kind of errors](http://stackoverflow.com/questions/2648533/php-doesnt-show-any-kind-of-errors) – ArtOfWarfare Nov 29 '14 at 17:14

12 Answers12

59

Don't just enable the first occurrence of display_errors in the php.ini file. Make sure you scroll down to the "real" setting and change it from Off to On.

The thing is that if you settle with changing (i.e. uncomment + add = On) by the very first occurrence of display_errors your changes will be overwritten somewhere on line 480 where it's set to Off again.

dbm
  • 9,888
  • 6
  • 41
  • 55
46

I had the same problem - solved it by setting display_errors = On in both php.ini files.

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

Then restarting Apache:

sudo /etc/init.d/apache2 restart

Hope this helps.

Rahil Wazir
  • 9,490
  • 11
  • 38
  • 61
Alex
  • 461
  • 4
  • 2
  • 2
    I think, cli is for online command line error whereas apache2 php.ini represents errors that show up in browser – madhu131313 Nov 06 '14 at 08:00
  • 2
    /etc/php5/apache2/php.ini = PHP-settings when run through the browser. /etc/php5/cli/php.ini = PHP-settings when PHP is run from the command line – Coreus Oct 29 '15 at 00:49
  • Omg!!! That's so obscure. Glad I found it, would give it +10 if possible. @JLove This should be accepted as the correct (complete) anwser. – Paulo Bueno Feb 29 '20 at 14:52
37

To make it work you should change the following variables in your php.ini:

; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off

; display_startup_errors
; Default Value: On
; Development Value: On
; Production Value: Off

; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT 
; Production Value: E_ALL & ~E_DEPRECATED

; html_errors 
; Default Value: On 
; Development Value: On 
; Production value: Off

; log_errors
; Default Value: On 
; Development Value: On 
; Production Value: On

Search for them as they are already defined and put your desired value. Then restart your apache2 server and everything will work fine. Good luck!

sticksu
  • 3,292
  • 3
  • 23
  • 39
  • 6
    I wonder whether everybody who upvoted this changed `php.ini` as suggested here or actually put the correct values in, e.g. `display_errors = On`. This is all comments on the default values, so if you actually uncomment the lines suggested here your php.ini will have syntax errors. – Pascal Nov 15 '12 at 06:35
  • @Pascal is right, that change will produce syntax errors and new changes in `php.ini` will not take effect. – Marcos Nov 29 '12 at 18:07
  • 9
    This answer is misleading. Chek dbm's answer down below for the correct configurations. – Chamara Keragala Oct 23 '13 at 05:03
8

After you edit /etc/php5/apache2/php.ini be sure to restart apache.

You can do so by running:

sudo service apache2 restart
ChrisC
  • 89
  • 2
5
  1. First you need to find the path to the php.ini file
  2. You will find the file in the specified path /etc/php/7.0/apache2/. If you are changing the values in the CLI folder or the CGI folder it will not work.
  3. Make the following changes

display_errors = On

  1. Restart you apache server

/etc/init.d/apache2 restart

Cyborg
  • 207
  • 5
  • 12
4

If you have Local Values overriding master values, you won't change its values in php.ini take a look for those variables in a .htaccess or in the virtual-host config file.

...

        php_admin_value display_errors On
        php_admin_value error_reporting E_ALL
</VirtualHost>

If you edit vhost, restart apache,

$ sudo service apache2 restart

.htaccess edits don't need apache to restart

Siraj Alam
  • 5,569
  • 5
  • 39
  • 55
juanmf
  • 1,867
  • 1
  • 24
  • 26
4

Follow the below steps,

1). Open your php.ini file via sublime through path 
    /etc/php/7.2/apache2/php.ini

2). find display_errors in that file

3). Un-comment these lines of code
      display_errors
      Default Value: On
      Development Value: On
      Production Value: Off

      display_startup_errors
      Default Value: Off
      Development Value: On
      Production Value: Off

      error_reporting
      Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
      Development Value: E_ALL
      Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

      html_errors
      Default Value: On
      Development Value: On
      Production value: On

4). Save the file and then type the following command in the terminal
     sudo service apache2 restart


your errors are now showing in the browser
Shahrukh Anwar
  • 2,004
  • 1
  • 18
  • 20
1

Use the phpinfo(); function to see the table of settings on your browser and look for the

Configuration File (php.ini) Path

and edit that file. Your computer can have multiple php.ini files, you want to edit the right one.

Also check display_errors = On, html_errors = On and error_reporting = E_ALL inside that file

Restart Apache.

Phil Rv
  • 53
  • 1
  • 1
  • 5
0

Look at error_reporting directive in php.ini.

duri
  • 13,813
  • 3
  • 41
  • 48
-2

I was just stuck on the same issue, when I've realized that I was using the open short tag form:

<? echo 'nothing will be print if no open_short_tag option is enabled'; ?>

You have to go to your /etc/apache2/php.ini file and set the short_open_tag = Off to On, then sudo service apache2 restart!

Cheers!

cl0udw4lk3r
  • 2,353
  • 4
  • 23
  • 42
-2

it's should overlap, so it turned off. Try to open in your text editor and find display_errors and turn it on. It works for me

-3

Try adding log_errors = Off and check the error_reporting setting whether it's set high enough.

CodeTwice
  • 2,756
  • 3
  • 15
  • 17
  • Are logging and displaying errors not two different things i.e. You'd have logging on in Production but you may not want to display errors in the browser? – JLove Feb 19 '11 at 11:23
  • I'd display errors on screen in production and logging when live. – yoda Feb 19 '11 at 11:27
  • I have worked with production environments which were preventing the displaying of errors unless log_errors was turned OFF. I don't know how exactly the paranoid sysadmin configured the box, but this solved it – CodeTwice Feb 19 '11 at 17:11