PHP only shows errors and no output - php

I'm having a hard time trying to get PHP to be in a state where I can debug errors. After finally managing to output errors (instead of Internal Server Error), I noticed that I don't get any output from before the error. If I try to var_dump the variable that is causing the error, I get nothing - just the output from the error, saying the was an error on some line. As you can imagine, this makes debugging extremely hard if not impossible.
Is there any option in the php.ini or somewhere else where I can change that? If it helps anything, I noticed that the error-messages are just plain-text even though the html_errors option in specified (according to phpinfo()). I'm running PHP 5.4.30 on a Windows Server 2008 R2 with Plesk. If you need additional information, I'll happily provide it :)
Thanks in advance

Related

http error 500 aws bitnami wordpress hosting [duplicate]

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.

Error 500 in FastCGI on PHP

I recently changed server.
This my new server using FastCGI to interpret PHP.
However, much that I brought from the old server is giving this error again, and the problem is that FastCGI does not return the error to debug, it just returns a "500 internal server error".
With that I'm not exactly sure what line to correct the error occurred.
I have scripts immense, which makes unfeasible review the entire a Code.
Already tried using
try {.. }
in known errors, but still FastCGI returns the 500 error.
I'm not a server administrator to power on mecher environment variables, is there any way to work around these errors from within PHP?
This error may be cause because you didn't set the proper permissions for the directory.
You should set the proper permissions and then try run the script. It should work.
Try running simple php file to see if it shows this error. If so then change permissions. If not then check the logs because the problem may be in your script.
You can also set display_errors to 1 in php.ini, htaccess or inside script
in php.ini look for error_reporting and display_errors
error_reporting = E_ALL
display_errors = 1
Put this inside your code, it'll turn error reporting on.
ini_set('display_errors',1);
error_reporting(E_ALL);
I had the same error, I had the proper permissions.
What fixed my problem was to download Visual C++ Redistributable for Visual Studio 2012 Update 4 x86.
I have PHP in x86 so I downloaded VSU_4\vcredist_x86.exe.
I had just x64 before solving my issue. Installing VSU_4\vcredist_x86.exe solved the problem and now I have both.
I hope it helps!
Yo can download VSU_4\vcredist_x86.exe here:
http://www.microsoft.com/en-us/download/details.aspx?id=30679

Is there an Easy out of the box solution to debug PHP?

I am writing a php web application and I get stuck because my script doesn't work how I would expect. Then I check the logs and I get nothing. My php.ini file is set to display all errors and log all errors. But I am not getting anything. On my mac, how can I debug PHP so I can step through the code and see what the problem is?
If you use apache then look into apache logs.

php return 500 error but no error log

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.

MYSQL queries not executing or not showing errors

Just installed a nginx server with ubuntu 11.04 and after loading my php program i was writing i noticed that no MYSQL queries run. I get no errores, either from PHP nor MYSQL.
The user my PDO connection uses has all priviledges.
When i change the host to any value, i do not get any error either.
I believe mysql is not showing any connection error. How do i check it's enabled? Just checked mysql.conf and i see nothing related to error reporting. Also looked php.ini and all error options are enabled, i also enabled it in-code.
I have no clue, it's useless to work with no kind of error reporting!
Thanks!
Where are your error logs for nginx? Have you looked in those? Is mysql running? Try service mysql status. PHP should still give you an error though if it can't connect to the database. How do you know the queries are not running? What I mean is, what are the symptoms? Maybe the queries are running but your input is bad?
Most important is to try to isolate the problem. 1) Use curl -v http://your_server to make sure nginx is actually serving the pages. 2) Set up a phpinfo.php file in the root web directory with <? phpinfo(); ?> and check the mysql settings and verify where log files for php are being written 3) Try installing phpmyadmin and see if you can connect to the database using that.
Each one of the above eliminates at least 1 of the elements (your program, PHP, nginx, mysql), helping you to narrow down the cause of your problem.
EDIT: Additional instructions for item 2. You are looking for the php error_log setting. If it is not set, the errors should go to stderr, which in this case I think would be your nginx log files (true at least for apache). You could also check that error_reporting is set to some reasonable value (try error_reporting=E_ALL for now). You can set both of these in your php.ini file, or in your program. See the manual in section PHP Error Handling Runtime Configuration. I would do a sanity check by triggering an error in my program at the beginning of the program and making sure the error shows up in the log file:
trigger_error('Want to be a rock star test message', E_USER_WARNING);
If you see your message, you've got the right log file and you should find your other errors (if any - mysql might not be the problem, could be bad input as I mentioned before).

Categories