-1

I'm setting up a LAMP stack in Vagrant (Ubuntu 16.04, Apache2, PHP7) and PHP isn't showing any errors. I have the following file that should return errors:

This is a PHP File
<?php thisisnotafunction(); ?>
<?php echo date("ThisIsAnInvalidArgument"); ?>

Other Stack Overflow posts (post 1, post 2, post 3) state that I need to change the php.ini file to display errors.

Running $ sudo find / -name php.ini returns:

/etc/php/7.0/apache2/php.ini
/etc/php/7.0/cgi/php.ini
/etc/php/7.0/cli/php.ini

I went into each one of those and set display_errors = On, restarted apache2, but still no errors. However, adding the follow to my index.php file does show errors:

<?php
    error_reporting( E_ALL );
    ini_set( "display_errors", 1 );
    require_once( "sample.php" );
?>

index.php now returns:

This is a PHP File 
Warning: require_once(sample.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 6

Fatal error: require_once(): Failed opening required 'sample.php' (include_path='.:/usr/share/php') in /var/www/html/index.php on line 6

So clearly my PHP setup knows how to deal with errors.

Community
  • 1
  • 1
reelyard
  • 931
  • 1
  • 8
  • 29
  • Apache directives can set or unset this flag, the ini might not be the one used by the install you have (nor does it have to be called php.ini, php7 can read directories of inis, etc, etc) – pvg Mar 31 '17 at 13:21

1 Answers1

1

Use php --ini command will show you using Configuration File.

mohe14
  • 47
  • 6
  • 1
    This confirmed which ini file PHP was using. Thanks. Also, for anyone else looking for an answer to this, it turns out that `display_errors` shows up **three times** in php.ini (twice normally and once as a comment). – reelyard Mar 31 '17 at 13:23