I have apache2 installed on my PC.
And php5 and all the stuffs.
The php is also running fine. I checked commands INSERT INTO myTable etc and it's working fine.
I've phpMyAdmin installed and it's also working fine.
The problem is that I'm not getting any error when there is actually error.
for e.g.
PHP :
<?php
<?php
$umair = 1
echo $umair;
echo 'asdf';
?>
This code isn't outputting anything. As you can see there is error of semicolon here and the PHP must show some error.
And if I put the semicolon then the PHP runs as usual and get the output 1asdf
Set your php.ini settings to display errors :
- error_reporting to E_ALL
- display_errors to on
(those are developement environment settings of course ; more about error_reporting levels here)
You can find your php.ini location using phpinfo() in a PHP script.
EDIT In case it isn't that, try to execute a valid script, and tell us if it runs correctly. If it doesn't, it probably means that your php module installation failed somehow.
EDIT 2 Restarting Apache will be necessary after editing such parameters.
You can try to show the errors for the current file that you're working on right now by adding
error_reporting(E_ALL);
and try to check this
The problem is that the missing ";" is a parser error - and parsing is done before execution.
PHP will simply not even start executing an invalid script - so you don't see anything.
Try to include this script in another script and run that - then you will get a clear error-msg!
Here's more on that topic and also my script to do this: How to get useful error messages in PHP?
Related
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
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
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.
Use error_reporting(1); or error_reporting(TRUE); and make sure no where you have disabled anything pertaining to error reporting
add this code in your php file
// Report all PHP errors
error_reporting(-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..
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);
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:
http://www.w3schools.com/php/func_error_reporting.asp
http://www.w3schools.com/php/php_ref_error.asp
http://php.net/manual/en/function.error-reporting.php
How to get useful error messages in PHP?
I'm trying to see what error PHP is producing. So I've changed the value of dispaly_errors to ON in the etc/php5/apache2/php.ini file.
The file doesn't display anything and I don't see any error on the webpages.
Am I missing any thing?
First, you have to make sure that this is your correct ini file. Usually the file you have used is the correct one. If not sure, you can create a simple PHP program to call the phpinfo() function and check this out.
Next, you have to restart Apache. Without a restart your settings don't take effect.
Another thing... This file can be a little misleading because there are so many comments in it. The actual line to change is way down. On my setup (LAMP/Ubuntu) the setting is on line 538.
Open php.ini file from your php folder, remove semicolon from all error reporting like
;error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT, ;display_errors=On etc, at last, restart your server, you will find all error messages.
Another way for showing error, you can write these codes in your script -
echo '<pre>';
error_reporting(E_ALL);
ini_set('display_errors', 1);
In addition to enabling display_errors, you may also need to set the error reporting level. if you are expecting errors with a script that is redirecting, be sure to turn off the redirection or you may never see them.
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
I'm painfully new to PHP, and was trying to set up phpBB on my local site. I have a stock debian install of apache2 and php5. The phpBB installer ran fine, connected to the database and created all its tables with no problem. But when I tried to open the login page, I got a 0-byte response.
A little digging showed that it was never making it past the call to mysql_pconnect(). The php binary just quits without error or message. Nothing at all. I tried running the following code:
<?php
$id = #mysql_pconnect('localhost','myusername', 'mypassword', true);
print "id=".$id."\n";
?>
and the "id=" string never prints. It just does nothing. I don't know where to look to see what error happened, or what is going on at all. All i've installed is "mysql" using pear... perhaps I'm missing something else?
This has got to be a path problem somewhere. The mysql extension is built nicely at
/usr/lib/php5/20060613+lfs/mysql.so
Answer:
jishi: informed me that the "#" operator suppresses output, including error messages (#echo off, anyone?)
tomhaigh: extensions must be explicitly enabled in php.ini file. After adding the line "extension=mysql.so" to php.ini, the following code runs fine:
% cat d.php
<?php
ini_set('display_errors', true);
error_reporting(E_ALL | E_NOTICE);
$id = mysql_pconnect('localhost','myusername', 'mypassword', true);
print "id=".$id."\n";
?>
% php -c /etc/php5/apache2/php.ini d.php
id=Resource id #4
JOY!
Just noted that you're using a # in front of mysql_pconnect(). That suppresses all errors, which in this case is a pretty bad idea. Remove that and you would probably see the output.
Otherwise:
Check your php.ini, should be in /etc/php5/apache2/php.ini for debian.
Check for a line called display_errors, set that to true if you want error-output in your browser (not recommended for a production-system, but is useful during debugging and development).
Specify log_errors on for apache to log your errors to apaches error logfile, which by default in debian would be (unless other error-file is specified for the phpBB-site):
/var/log/apache2/error.log
try doing this:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL | E_NOTICE);
$id = mysql_pconnect('localhost','myusername', 'mypassword', true);
print "id=".$id."\n";
?>
and see what the response is
edit
From your comment it looks like the mysql module is not installed or enabled. You could have a look in your php.ini file and see if there is a line like
extension=mysql.so
If it is commented with a semi-colon, try removing it and restarting apache
Remove the "#" That is muting the error messages that mysql_pconnect is throwing.
Documentation
I sometimes have PHP going down a 'black hole' when it finds a function that it can't find.
Can you verify that the mysql extension is installed correctly?
You can do this by creating a php page like this:
<?php
phpinfo();
?>
Saving it in your webroot, and then accessing it. It should contain all the information about what your server is currently running in terms of PHP modules.
I think you have no mysql extensions installed for your PHP. Since PHP5 I think it is a PECL extension.
If you are working on windows, there should be a pecl.bat or something like this in your php directory. Just go there via console and enter
pecl download mysql
Then everything should work as expected.