4

Here is my simple codes file in /var/www/read.php :

error_reporting(E_ALL);
<?php
    echo hello"
?> 

I ran across the error reporting when to run `php /var/www/read.php ' on debian console.

PHP Parse error:  syntax error, unexpected '"', expecting ',' or ';' in /var/www/read.php on line 3

But there is no error reporting in web page when to input 127.0.0.1/read.php in firefox.

I have set the values in php.ini as following:

error_reporting = E_ALL & ~E_NOTICE    
display_errors = On  

It is no use for me to restart apache2 with command :

service apache2 restart

Here is my phpinfo message. It is no use to add two lines in my read.php file,no error message reported in my firefox.How can i fix it?My system is debian7+php .

<?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    echo hello"
?> 

find  /  -name  'php.ini'
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

The problem solved according to PHP doesn't show any kind of errors

enter image description here enter image description here enter image description here

Community
  • 1
  • 1
showkey
  • 449
  • 30
  • 101
  • 235
  • Sounds like those php configuration options are not active. Either you have not restarted your php environment (usually the http server) after changing them, or the php engine uses another configuration file than the one you modified. You can check that using phps `phpinfo()` function: http://php.net/manual/en/function.phpinfo.php – arkascha Mar 14 '15 at 08:10
  • can you post the path of the php.ini file that you are edited? – Adrian Cid Almaguer Apr 25 '15 at 00:19
  • /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini – showkey Apr 25 '15 at 00:30
  • you was modified /etc/php5/apache2/php.ini or /etc/php5/cli/php.ini ? – Adrian Cid Almaguer Apr 26 '15 at 00:34
  • did you even try googling this? see the answer here with 9 upvotes: http://stackoverflow.com/questions/10083533/how-to-have-php-display-errors-ive-added-ini-set-and-error-reporting-but-jus your error reporting will never get called because the script is not executed due to the parse error –  Apr 27 '15 at 02:08

6 Answers6

5

First, the error_reporting() function should be moved inside the <?php ?> tags.

There are usually two php.ini files in a typical setup (One used by the webserver, other one used by the command line).

On a unix distribution, it is usually located somewhere below the /etc/php folder, like that for example /etc/php/apache2/php.ini.

To be sure what configuration file is loaded for PHP by the webserver, do a simple phpinfo(); in a webpage and just search for configuration file.

If you modify the one used by your websever, make sure to restart Apache afterwards, so it loads the new configuration.

If you want to enforce programmatically setting, you can use the ini_set function.

In your case, if you want to see any error on the page.

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

foobar();

Update :

Adding ini_set('display_errors', 1); won't do anything if there is a syntax error in the page, because the syntax error is thrown before the execution of the script. Try to create another type of error, e.g. call an unknown function instead, and you should see it.

alfallouji
  • 1,140
  • 8
  • 12
  • it is no use for me to add the two lines in my php file,error reporting still not to display on my firefox web page. – showkey Mar 14 '15 at 09:13
2

Use error_reporting(1); or error_reporting(TRUE); and make sure no where you have disabled anything pertaining to error reporting

Praxis Ashelin
  • 4,983
  • 2
  • 16
  • 43
Thyagi
  • 172
  • 1
  • 6
1

add this code in your php file

// Report all PHP errors
error_reporting(-1);
Neelesh
  • 193
  • 12
1
//To show errors
ini_set('display_errors', 1);
error_reporting(E_ALL);

//To hide error 
ini_set('display_errors', 0);

You also set this is in a common php file or in working file..

0

You should see which php.ini is read by Apache. It is common for console to use a different php.ini than Apache.

You can phpinfo() and see which configuration file is being read by Apache.

However, at the beginning of the read.php file add the following line:

init_set("display_errors", 1);
Mostafa Talebi
  • 7,115
  • 14
  • 48
  • 90
0

PHP has a nasty habit of giving the white screen of mystery when the error is syntax related. To get around this you can use the include function:

<?php
    ini_set('display_errors',1); 
    error_reporting(E_ALL);
    include "/var/www/read.php";
?> 

Now the syntax error is no longer in the first page and PHP can "compile" it will give you an error message about the broken page.

There are a couple of issues with the first code sample which should look like this:

<?php
    error_reporting(E_ALL);
    echo "hello";
?> 

First error reporting directives like all PHP code needs to be inside the PHP code tags. This should result in the code simply ending up on the page in Firefox which is not what you want.

Second echo acts on a string which should start and end with a quote mark. This is a syntax error and at the heart of the no error message problem.

Third all line must end with a semi colon (with the exception of a few block level commands). If in doubt... This is actually not your problem and you code will run without it as long as the code section terminates with a ?> as PHP will assume ; for you. However get intot he habit of putting you ; in place every time and you will not be tripped up by it later.

Now assuming that you are not on a host running in safe mode then you can turn on error reporting at the ini level in your code too

<?php
    ini_set('display_errors',1); 
    error_reporting(E_ALL);
    echo "hello world";
    unknownfunction() // this will throw errors
?> 

Judging by the fact that you have full control of the system I would say that you should know if you put safemode on. Also I see that you tried the above ini directive to no available (this is due to the syntax issue that I explained at the start of the answer).

Here is some further reading that might be of interest:

Community
  • 1
  • 1