Drupal + Nginx + Php-cgi : 502 Bad Gateway error - php

We are running Drupal 5.x on Nginx with php-fastcgi.
Things were working fine for a while. All of a sudden, we (users) are running into 502 Bad Gateway error.
Restarting PHP-cgi, nginx.. rebooting machine etc did not help.
Did anyone else run into this type of issue? What are the possible suspects?

Today I was getting “502 Bad Gateway” on a CI project , after digging into the problem I found out it is a problem of nginx fastcgi buffers , here is how to fix it :
open /etc/nginx/nginx.conf
add the following lines into http section :
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

502 errors are usually caused when PHP freaks out for some reason. The first thing you should do is check all of your logfiles. That includes system stuff in /var/log/ and the nginx logs.
If you haven't made any recent changes and the problem just started happening for no apparent reason, PHP may be running out of memory. I know when it happens as an Apache module it gives a blank screen--wouldn't be surprised if a 502 error happened under nginx and the FastCGI interface. That's easy to fix by putting ini_set('memory_limit', '256M') into your index.php and see if that fixes the problem.
Also, can you load stand alone PHP files that don't involve Drupal? Put putting <?php phpinfo(); ?> into a file called info.php and try hitting that and see what happens.
Good luck!

I got this error as well and I eventually disable all modules (non-core) and enable them one by one to see what caused the error.
Here's a easy way to disable all non-core modules.

If the problem just started.. Read above.. if the server is new just setup, try this command to see if it's even listening on it's port
netstat -lpn | grep ":9000"
If course you could have setup fast-cgi to work on a different port, so just replace the port 9000 in that statement with what ever port you're looking for.. If nothing continues to show up, likely nothing is listening on that port and you need to fix that problem first.

If you have firePHP disable it.
Big headers causes problems while nginx comunication with php

Usually when I have come across this it has been a fatal error in PHP somewhere. Have a look at your PHP-cgi log to see if it is in there. There should be something in the nginx log like this: 104: Connection reset by peer. Depending on your setup this (sorry, link dead) might help but if you're using php-fpm it won't.

increase your memory limit and it will be fixed. ini_set('memory_limit', '256M');

It is because you probably upgraded to PHP 5.5 and therefore you now are using opcode cache which you may have enabled twice. That is check php.ini and also opcache.ini.

Related

Apache in MAMP Pro 4 has stopped working, refuses to start

Have been using MAMP Pro for a fair while - version 3 primarily, upgraded to 4 a while ago.
I haven't had any unusual issues at all, but today the Apache service failed to start, telling me to check the error logs. The logs were blank unfortunately... I've made no system configuration changes, no changes to MAMP/MAMP Pro. Shut down my system yesterday, started today, it no longer works...
I've tried numerous suggestions found via Stack Overflow and Google without any success.
Even after completely uninstalling and re-installing MAMP Pro I am unable to get the service to start.
Nothing appears in the logs...
When starting it manually on the command line it comes up with a PHP related error:
$ Applications/MAMP/bin/apache2/bin/apachectl start
httpd: Syntax error on line 135 of /Applications/MAMP/conf/apache/httpd.conf: Cannot load /Applications/MAMP/bin/php/php5.2.17/modules/libphp5.so into server: dlopen(/Applications/MAMP/bin/php/php5.2.17/modules/libphp5.so, 10): image not found
The confusing thing is that I don't have PHP 5.2.17 specified anywhere, at all - according to MAMP Pro it should be using PHP 7.0.12.
If I add PHP 5.2.17 to MAMP using the appropriate MAMP Pro dialogs, Apache still fails to start via the MAMP Pro interface. I can now start it manually from the command line however, but none of my virtual hosts/etc seem to be loaded.
apachectl -V tells me it's using /Applications/MAMP/conf/apache/httpd.conf, but there is nothing in that file that has any reference to any of the configs generated in /Library/Application Support/appsolute/MAMP PRO/conf
It also looks like hosts entries aren't added to /etc/hosts.
Even if I tell /Applications/MAMP/conf/apache/httpd.conf to do nothing but include /Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf (and manually add entries to /etc/hosts) it still doesn't seem to work at all...
I and my colleagues are at a complete loss, especially given it was working yesterday...
Has anyone had any issues like this?
I managed to fix the similar issue you had.
My Apache server was working fine and then following updating to 4.0.6 I experienced similar issues.
There were 2 things I did to fix the issue. I was getting the same error where it couldn't find a php file in 5.2.17. After fixing that by adding 5.2.17 to MAMP I experienced an apache error regarding user permissions.
(22)Invalid argument: getpwuid: couldn't determine user name from uid 4294967295, you probably need to modify the User directive
File > Edit Template > Revert ALL Templates to Default Settings.
Save & restarted the servers and all worked finally and all my hosts had retained as well.
I had previously entered a custom line in my httpd.conf file that for countless versions had copied across fine however it looks like the folder structure had changed and so couldn't locate it causing the unusual error about User permissions. I have since re-entered the custom line with the correct structure and all working fine again.
Hope this helps.

APACHE server run slow suddenly

I'm using Apache for my localhost, bot now it's slowed down without any error suddenly, each time I start load a page it takes more than 1 minute , I do see any uncommon error in the error log , and my PHP code is also run perfectly without error.
I had tried several solution like adding localhost, enablemmap on off, setting only IPv4 but and non of it helping.
Is that anything more i can try to fix this ?
I fixed it by re-installing Apache server.

Using session->set_flashdata causes 502 Bad gateway error

I am getting 502 bad gateway error when ever I use
$this->session->set_flashdata('message', 'Profile updated.');
I am using CodeIgniter on nginx. The code runs fine on localloast(WAMP). If I comment out the lines, application runs fine.
Any help will be appreciated.
in application/config/config.php set "use_database" to TRUE
I figured out what was wrong. First of all, a colleague with more server knowledge explained me that my setup probably was such that nginx received all the requests, and then directly served static files. for non-static request, it passed on the work to apache, and serves as an intermediary. So probably something went wrong when apache tried to send data to nginx (or when nginx tried to send information to apache).
As I never worked with nginx before, I also did not think of checking the nginx log files. And there was an error that I could use:
[error] 27453#0: *9223 upstream sent too big header while reading response header from upstream, client:
I ended up applying the first bit of this other stack overflow solution:
Add this to your nginx.conf file normally located at
Code:
/etc/nginx/nginx.conf:
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
By the way, it should be added to the http section of the file. That was something what was missing from the solution.
Reference:
https://forum.codeigniter.com/archive/index.php?thread-59675.html
from #sasho 's answer
$config['sess_use_database'] = TRUE;
By changing into database you can move session data to database's table to avoid permission related problems. Try and reply here.
https://www.codeigniter.com/user_guide/libraries/sessions.html
You can see the database driver section from the official documentation to avoid these kind of errors.

Multiple Eaccelerator Issues

General info
Linux Centos GoDaddy VPS with Prestashop Ecommerce site
Issues created by Eaccelerator
1) Since installing eaccelerator, the php related wait time has risen 500 ms and I have no idea why.
Before Eaccelerator Installation: http://tools.pingdom.com/fpt/#!/zdViZURr3/http://www.kikbo.com/buy
After Eaccelerator Installation:
http://tools.pingdom.com/fpt/#!/NrPauzEMD/http://www.kikbo.com/buy
2) When using the following php.ini configuration, I get a 500 internal server error whenever I go to any of the dynamically generated pages on my website.
[eacclerator]
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="1" [set as 1 to check the errors]
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
When I check the error_log, it tells me eaccelerator is caching but gives me no further indication as to why its causing a 500 internal server error.
EACCELERATOR cached: "...index.php"
3) When I change this:
extension="eaccelerator.so"
to this:
zend_extension="/usr/lib64/php/modules/eaccelerator.so"
I cease to receive the 500 internal server error and eaccelerator shows up in phpinfo(). After someone visits the site, scripts get cached, but they don't stay that way. They disappear quickly and "scripts cached" becomes 1, and "scripts removed" becomes 0.
(source: kikbo.com)
Further, when I command line: php -v I don't see anything about eaccelerator. And even further, I see no benefit in php computing time.
When I check the error log I now see eaccelerator caching and getting "hit":
EACCELERATOR hit: "...index.php"
EACCELERATOR cached: "...config.inc.php"
My questions
Is there some way I can "undo" this eaccelerator installation? It slowed down my website and I can't sort out why. It seems like I should be using APC...but in any case can these problems be corrected and if so what is causing them?
Do you really need to uninstall it or will just disabling it do what you need? If you set the enable key to 0 then eaccelerator won't be used.

oci_connect Blank Page in PHP

UPDATE (5/21/2010) SUCCESS!
So after MUCH $head->desk()'ing, I've solved it.
Remember kids, be wary of the instant client version you use, dependent on the virtualization settings!
I had been installing the generic Instant Client (not aware our ESX servers sit on AMD processors, not Intel) and that worked fine internally (the CentOS install was 32-bit since our internal ESXi servers aren't 64-bit). Well lo-and-behold, even if you have a 32-bit install running on a virtualized server which is sitting on an AMD64, it still matters what instant client you install.
It was the last thing I thought to check but as it appears, everything is running fine now.
I would like to thank everyone who helped me run through every possible test to figure this out but in the end, it was my fault for not realizing the differences in the virtualizations.
UPDATE (5/21/2010)
I thought this bug had escaped me when I installed it on a new VM internally but I have now found a narrowing link.
I was trying to install this on our production server when I posted this. After a week of no progress and in need to get back to development, I outfitted a VM on our internal server with a brand new install of Crap... CentOS, and fresh installs of instant client and oci8.
Worked perfectly.
However we just uploaded an exact copy of the VM to our production servers and it magically no longer works. Tried reinstalling everything, no avail.
So the only things I could narrow it down to is a firewall issue (although I get the same issue when trying 127.0.0.1) or possibly an ESX (our production servers) server issue, internal servers are running ESXi.
Any thoughts?
UPDATE (3/8/2010) I installed Xdebug and have it tracing my code. This is the output I am getting:
TRACE START [2010-03-08 17:53:05]
0.2090 327864 -> {main}() /data/aims3/http/octest.php:0
0.2091 327988 -> ini_set(string(14), string(1)) /data/aims3/http/octest.php:3
0.2093 327920 -> error_reporting(long) /data/aims3/http/octest.php:4
0.2094 328048 -> oci_connect(string(8), string(8), string(25)) /data/aims3/http/octest.php:6
The trace halts at that point.
I have installed everything the same way on a local server and it works fine. To say I am at a complete loss would be putting it lightly.
*NOTE: I ran make test and it returned FAIL on every test. I never ran this on my working machine to see if it reports the same errors. Any idea why make test would report FAIL but make doesn't report any error?
I've installed the Oracle Instantclient with no reported errors along with the OCI8 PECL package and at a loss. Whenever I try to open a connection with oci_connect, it halts my entire PHP script.
EXAMPLE:
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
echo "before";
$conn = oci_connect("username", "password", "host");
echo "after";
?>
Returns a complete blank page. The module is loaded (seen in phpinfo) and everything installed with no errors.
I am at a complete loss.
CentOS: 5.4
Apache: 2.2.3
PHP: 5.3.1
InstantClient: 11.2
oci8: 1.4.1
Any thoughts?
NOTES
Apache Error Log reports nothing
Attempted Debugging:
1:
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
echo "before";
if(!function_exists('oci_connect')) die('Oracle Not Installed');
echo "after";
?>
Returns:
beforeafter
2:
Changing host to //host
Returns:
Same error
Is there anything in Apache's error_log? Is this mod_php or FastCGI or normal CGI PHP? What happens if you run the script via the command line?
You could also try setting PHP's error log and looking in there.
EDIT1: Try:
echo "before";
if(!function_exists('oci_connect')) die('Oracle Not Installed');
And post the results...
EDIT2: I'm really not sure. My best bet is this info from the PHP manual:
The most common problem with
installing OCI8 is not having the
Oracle environment correctly set. This
typically appears as a problem using
oci_connect() or oci_pconnect(). The
error may be a PHP error such as Call
to undefined function oci_connect(),
an Oracle error such as ORA-12705, or
even an Apache crash. Check the Apache
log files for startup errors and see
the sections above to resolve this
problem.
Anyone else have any ideas to help out Bryan?
Bryan,
I am going to be honest: I tried this two years ago and failed miserably. :) I could not get the OCI functions to work for anything by compiling myself.
But in the interest of getting it done I looked for an alternate solution and found it in Zend Core for Oracle. All I did was download, run the installer, and it was done. It installs Apache/PHP, MySQL (optional), and the InstantClient for you.
Now as Zend Server, it is basically the same product. I realize that this may not be the solution you hoped for, but if it works...
Zend Server
are you connecting to remote or to local db? i think, for localhost you must replace "host" with "false". I hope, this will help you...
edit: i think, you are missing a parameter...my last suggestions are: 1. you must set the port (default 1521) AND/OR 2. You must enter db name AND/OR you must set the instance name (the ORACLE_SID parameter)
You never check the return value of oci_connect() or call oci_error() but it doesn't look relevant to your problem since you seem to be suffering from a PHP crash. There's an open bug for RHEL that may affect you too:
http://pecl.php.net/bugs/bug.php?id=16626
Did you build the oci8 package yourself? Are you using a third-party binary?
It has been fixed. See the top for details but here is the cliff notes: virtualiztion environments matter.

Categories