Error 500 in FastCGI on PHP - 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

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.

How to change a setting to true in a PHP file?

I have an Apache2 web server with PHP 5.5 installed.
My default PHP settings is display_error = 0 (I don't need globally displayed errors) but I need it on in specific PHP files.
I tried with:
error_reporting(E_ALL);
ini_set("display_errors", 1);
and it's not working.
Can someone tell me how can I make it show errors in specific PHP files?
i am try to force some error writing some no syntax logic and not showing error...
To show parse errors in PHP you have to put this on your php.ini
display_errors = on
My advice is to avoid displaying errors on production servers but log them all. So you can later inspect and fix bugs from yoursite-error.log file.
You should be concerned if your applications has warnings, errors etc. IMHO it is a bad idea to focus your attention only on few files instead of them all.
Although display_errors may be set at runtime (with ini_set()), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.

Stop printing php error messages to browser

I'm using PHP 5.3, CentOS 6.2, httpd 2.2.15, NetBeans 7.0.1 (running remotely via ftp).
I want to stop printing error messages to the browser, it's enough that it prints to the error_log of httpd.
I thought by doing try/catch I would decide on my own how to handle the error but it still prints to both error_log and browser.
function smic_gettext($phrase){
try{
$tr_text = $this->language_array[$phrase];
} catch(Exception $e){
error_log("Couldn't find any entry in the translation file for ".$phrase.". ".$e);
return $phrase;
}
return $tr_text;
}
How should I configure in order to stop this behaviour?
I have tried setting display_errors=Off and display_errors=0 in php.ini. No difference (I did restart httpd).
display_errors = Off
in php.ini will let you keep your syslog errors, but write nothing to the browser.
You need to change the php.ini setting display_errors to off or 0. You can either do this in your actual php.ini, with a .htaccess file, or by calling this at the start of the script:
ini_set('display_errors', '0');
Try adding the following to the top of your script:
ini_set('display_errors',0);
This should set the error reporting to none and override the servers php.ini settings (which sometimes ignore your error_reporting(0) )
Wheter or not PHP errors are sent to the browser is determined by the php.ini setting: display_errors. Set it to Off to avoid it being output. This file is usually located under /etc/php.ini or /etc/php5/php.ini
If error appears only in one line it is possible to prevent error display with adding sign # to start of that line.
#YOUR_CUSTOM_COMMAND
Example:
#file_get_contents('custom_file.txt');
See display_errors directive
http://www.php.net/manual/en/errorfunc.configuration.php
If you want to hide errors and warnings, you can also set an error_handler.
See http://php.net/manual/function.set-error-handler.php
FWIW, while display_errors = off is the correct config-file line as others have said, on DreamHost (nd possibly other installations), it goes in
$HOME/.php/phprc
rather than php.ini (which might also work, but DreamHost -- and, again, possibly others -- supports phprc).

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.

PHP warnings cause script to halt on IIS running FastCGI

We are migrating to a new server running Windows 2003 and IIS 6. When my PHP code runs, it has a warning on a particular line (which I'm expecting at the moment but will fix shortly). However, when it hits the warning, it immediately halts processing and returns a 500 error in the HTTP header. Normally, I would expect PHP to output the warning, but continue processing the script.
Is there something in the configuration for IIS, FastCGI, or PHP that would be returning 500 errors when PHP hits a warning?
To clarify: I don't want to suppress the warnings; I want them to display. I do not want the script to stop processing on warnings.
Figured out the issue. log_errors in php.ini was set to On, but error_log was unset. This was causing PHP to stop everything. After setting display_errors to on, the warnings now display so I can see where things are breaking in the output.
This thread was helpful: http://forums.iis.net/p/1146102/1856222.aspx#1856222
I don't know about IIS or FastCGI, but afaik php has no such option. You can however set error_reporting (in your php.ini) to
E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
to make warnings go away.
That depends very much on your PHP code as well, if you are doing something complicated within the code and an error occurs, web servers sometimes throw 500 errors. I would suggest you:
Put an # on the line to suppress the error, i.e :
$x=#my_function($y);
See your web server logs for the exact error message you get, then post it here and perhaps we could offer you a better solution.

Categories