1

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";
?>
Caleb
  • 11,813
  • 4
  • 36
  • 49
Richard
  • 13
  • 1
  • 5

2 Answers2

0

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

gravyface
  • 13,957
  • 19
  • 68
  • 100
  • I tried this and it's still not displaying errors – Richard Apr 20 '11 at 00:05
  • Did you restart Apache? – gravyface Apr 20 '11 at 00:11
  • I had not, but I just restarted apache and tried it again. Still no errors :( – Richard Apr 20 '11 at 00:13
  • Is there something I need to configure in my vhost file? – Richard Apr 20 '11 at 00: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 00:19
  • Yeah, I wonder what's wrong – Richard Apr 20 '11 at 00:23
  • Ok, brain fart. Just did an install of PHP5 and apache2 on another Ubuntu 10.04.2 LTS virtual machine, changed `display_errors` to `On`, created foo.php with `` and sure enough, "Parse error: syntax error, unexpected T_VARIABLE". – gravyface Apr 20 '11 at 00:24
  • Hmm, so it's working for you on a fresh install. I wonder what I did to mess it up. I've changed nothing but the vhost settings. – Richard Apr 20 '11 at 00:28
  • OK, It works if i place use the ini_set method in my PHP file. But how come the php.ini directive isn't working? Is there any place I could place the configuration? – Richard Apr 20 '11 at 00:31
0

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

chrishiestand
  • 974
  • 12
  • 23