Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I just tried a simple hello world with a semi colon missing, and I'm getting a blank page.

Any ideas why PHP refuses to show errors?

A script without errors works perfectly.

Also, I remember reading somewhere that there's an example config file that Apache or PHP come with that needs to be renamed to remove the .sample or something like that.

Since I'm not much of a server admin, I'd much rather go with whatever sample Apache/PHP has provided. Where can I find this sample configuration? Perhaps it'll fix this (and other problems yet to appear).

PHP script I'm testing with (missing semicolon)

<?php
    echo "Hello"
    echo "sup";
?>
share|improve this question

2 Answers 2

up vote 0 down vote accepted

Set display_errors = On in /etc/php5/apache2/php.ini.

share|improve this answer
    
I tried this and it's still not displaying errors –  Richard Apr 20 '11 at 0:05
    
Did you restart Apache? –  gravyface Apr 20 '11 at 0:11
    
I had not, but I just restarted apache and tried it again. Still no errors :( –  Richard Apr 20 '11 at 0:13
    
Is there something I need to configure in my vhost file? –  Richard Apr 20 '11 at 0:13
    
Odd, I can't seem to turn "off" error outputting now and I'm sure I crossed the same bridge as you a couple of weeks ago with Ubuntu 10.04.2LTS/PHP and found display_errors. –  gravyface Apr 20 '11 at 0:19

In /etc/php5/apache2/php.ini, you need both

display_errors = On
error_reporting = E_ALL | E_STRICT

and maybe even

display_startup_errors = On

E_STRICT is not strictly necessary, but I think it's best practice to report those too.

However, you should only do this on a development server. Displaying errors can lead to security problems such as leaked passwords. You may want to be setting these values in your web app's configuration section - based on whether the web server is a development or production server.

  if ($_SERVER['SERVER_NAME'] == 'my.production.url') {
    ini_set('display_errors', false);
  }
  else {
    ini_set('display_errors', true);
  }

Note that $_SERVER['SERVER_NAME'] may not be reliable if virtual hosting is configured such that you can also load the website via an IP address. In this case, substitute an alternative test that works in your environment (eg getting the server's hostname, or testing to see if the REMOTE_ADDR is localhost).

share|improve this answer
    
Hey dimmer, I tried all 3 directives you've listed above, and errors still will not display. I've updated my post to show the PHP script I'm testing with. –  Richard Apr 20 '11 at 0:24
    
Update provided on gravyface's answer –  Richard Apr 20 '11 at 0:31
    
Are you testing via the web server or command line? –  chrishiestand Apr 20 '11 at 1:08
    
I'm testing via web server –  Richard Apr 20 '11 at 1:14
    
If you haven't already try restarting via /etc/init.d/apache2 restart - sometimes apache2ctl doesn't get the job done. –  chrishiestand Apr 20 '11 at 1:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.