# Php-fastcgi always exits resulting in 502 bad gateway

**URL:** <https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110>\
**Category:** NGINX\
**Created:** [September 22, 2011, 12:44pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110 "2011-09-22T12:44:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 22, 2011, 12:44pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/1 "2011-09-22T12:44:53Z")

</div>

Hello everyone,

I’m using nginx since some days and I got a little trouble. It seems  
that after some while of working fine nginx exits the fastcgi-daemon and  
whenever I try to call a php site then, it shows me 502 Bad Gateway.

Then I have to “/usr/bin/php-fastcgi start” and everything runs fine  
again.

So basically my question: How do I make the php-fastcgi not exit itself  
or how do I make it automatically restart on exit? It’s annoying that my  
website everytime turns to “502 Bad Gateway” to everyone and I don’t  
even know about that!

Can anyone help me please? ☹

Posted at Nginx Forum:

> **[php-fastcgi always exits.. resulting in 502 bad gateway](https://forum.nginx.org/read.php?2,215576,215576#msg-215576)**
>
> Hello everyone, I'm using nginx since some days and I got a little trouble. It seems that after some while of working fine nginx exits the fastcgi-daemon and whenever I try to call a php site then, it shows me 502 Bad Gateway. Then I have to...

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 1:29pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/2 "2011-09-22T13:29:30Z")

</div>

> So basically my question: How do I make the php-fastcgi not exit itself or how  
> do I make it automatically restart on exit?

Best way to do it is to use inbuilt process manager PHP-FPM  
[PHP: FastCGI Process Manager (FPM) - Manual](http://www.php.net/manual/en/install.fpm.php) (since 5.3.x its in php  
core).

rr

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 1:45pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/3 "2011-09-22T13:45:02Z")

</div>

I’m running Debian Lenny which has only php 5.2 ☹

I tried apt-get install php5-fpm and php-fpm, but both don’t work. How  
to get it on Debian Lenny? I cant compile php on my own… ☹

Posted at Nginx Forum:

> **[Re: php-fastcgi always exits.. resulting in 502 bad gateway](https://forum.nginx.org/read.php?2,215576,215588#msg-215588)**
>
> Hello everyone, I'm using nginx since some days and I got a little trouble. It seems that after some while of working fine nginx exits the fastcgi-daemon and whenever I try to call a php site then, it shows me 502 Bad Gateway. Then I have to...

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 1:56pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/4 "2011-09-22T13:56:12Z")

</div>

On Sep 22, 2011 6:44 PM, “Lintu” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m running Debian Lenny which has only php 5.2 ☹
> 
> I tried apt-get install php5-fpm and php-fpm, but both don’t work. How  
> to get it on Debian Lenny? I cant compile php on my own…

Install supervisord. You can then create as many php-cgi processes using  
supervisord which will be automatically restarted upon killed.

I usually use virtualenv to create dedicated python environment for  
supervisord.

- extract virtualenv to /opt
- create supervisord environment by issuing  
/opt/virtualenv/virtualenv.py /opt/supervisor
- install supervisord  
/opt/supervisor/bin/easy\_install supervisor
- configure accordingly (check its documentation)

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:09pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/5 "2011-09-22T14:09:15Z")

</div>

Hey, thanks for the tip with supervisord.

I found a site  
([Using supervisord for Nginx+FastCGI+PHP :: Sacha Chua](http://sachachua.com/blog/2010/06/using-supervisord-for-nginxfastcgiphp/))  
saying its easy to set up with:

> apt-get install python-setuptools  
> easy\_install supervisor

And actually it was. No error on that. But then the site says I should  
add something to /etc/supervisord.conf, but there is no file like that?  
I created it with the content I got told to, but well, nothing happens  
now… Or is everything fine now? Is everything automated about  
supervisord?

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,215576,215593#msg-215593](http://forum.nginx.org/read.php?2,215576,215593#msg-215593)

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:11pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/6 "2011-09-22T14:11:43Z")

</div>

From: Lintu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I’m using nginx since some days and I got a little trouble. It seems  
> that after some while of working fine nginx exits the fastcgi-daemon and  
> whenever I try to call a php site then, it shows me 502 Bad Gateway.  
> Then I have to “/usr/bin/php-fastcgi start” and everything runs fine  
> again.  
> So basically my question: How do I make the php-fastcgi not exit itself  
> or how do I make it automatically restart on exit? It’s annoying that my  
> website everytime turns to “502 Bad Gateway” to everyone and I  
> don’t even know about that!

We use spawn-fcgi here.

JD

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:24pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/7 "2011-09-22T14:24:06Z")

</div>

On Thu, Sep 22, 2011 at 7:08 PM, Lintu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> add something to /etc/supervisord.conf, but there is no file like that?  
> I created it with the content I got told to, but well, nothing happens  
> now… Or is everything fine now? Is everything automated about  
> supervisord?

run supervisorctl or just use ps check if the php-cgi processes are  
running. Set nginx fastcgi\_pass to whatever path you set in  
supervisord for php-cgi.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:25pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/8 "2011-09-22T14:25:57Z")

</div>

On Thu, Sep 22, 2011 at 7:22 PM, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > And actually it was. No error on that. But then the site says I should  
> > add something to /etc/supervisord.conf, but there is no file like that?

the basic config can be generated by command echo\_supervisord\_conf  
(you need to copy-paste the result or pipe it to file).

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:32pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/9 "2011-09-22T14:32:45Z")

</div>

On 22 Set 2011 11h44 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello everyone,
> 
> I’m using nginx since some days and I got a little trouble. It seems  
> that after some while of working fine nginx exits the fastcgi-daemon  
> and whenever I try to call a php site then, it shows me 502 Bad  
> Gateway.
> 
> Then I have to “/usr/bin/php-fastcgi start” and everything runs fine  
> again.

> So basically my question: How do I make the php-fastcgi not exit  
> itself or how do I make it automatically restart on exit? It’s  
> annoying that my website everytime turns to “502 Bad Gateway” to  
> everyone and I don’t even know about that!
> 
> Can anyone help me please? ☹

Use one of the many init scripts available throughout the  
interwebs. Also I suggest monit for monitoring the process.

I now use php-fpm, but before I used the “regular” php-cgi with this  
init script: [GitHub - perusio/php-fastcgi-debian-script: An init script to launch PHP the FastCGI daemon and spawn when needed in Debian · GitHub](https://github.com/perusio/php-fastcgi-debian-script) and  
a monit configuration for monitoring it:  
[monit-miscellaneous/php-cgi at master · perusio/monit-miscellaneous · GitHub](https://github.com/perusio/monit-miscellaneous/blob/master/php-cgi)

HTH,  
— appa

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 7:48pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/10 "2011-09-22T19:48:25Z")

</div>

## Reinis R. Wrote:

> rr
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

I used to do this and I hat php 5.3 running with apache. But when I  
decided to try something new to go with nginx instead of apache, I had  
trouble setting up nginx with php as that repository doesnt have the  
php-cgi package. Therefor all attempts to get any phpinfo() file run  
failed and I was forced to uninstall php 5.3 to install php 5.2. I  
wasn’t really happy with that, but at least it works at all… So far  
I’m only half-satisfied with nginx, but I’m pretty sure thats just about  
the config, nginx sounds fine. Gonne read tons of HowTos and Docs and  
stuff I suppose

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,215576,215649#msg-215649](http://forum.nginx.org/read.php?2,215576,215649#msg-215649)

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 8:19pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/11 "2011-09-22T20:19:58Z")

</div>

> as that repository doesnt have the php-cgi package.

You don’t need the -cgi (it is the old naming when fastcgi was built in  
the  
cgi sapi) package but ‘php5-fpm’ .  
Also I think the packages are prefixed with ‘php5’ and called php5-fpm /  
php5-cgi ( [http://php53.dotdeb.org/dists/lenny/php5/binary-amd64/](http://php53.dotdeb.org/dists/lenny/php5/binary-amd64/) )

rr

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 2:46pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/12 "2011-09-22T14:46:26Z")

</div>

> I’m running Debian Lenny which has only php 5.2 ☹

I’m not a Debian user but you could add the dotdeb repo (  
[PHP 5.3.8 is available | Dotdeb](http://www.dotdeb.org/2011/08/30/php-5-3-8-is-available/) ).  
Sticking with old and unsupported php release isnt a good thing.

rr

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 10:51pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/13 "2011-09-22T22:51:31Z")

</div>

So I removed php again, putting dotdeb into sources and commenting  
debian out, trying to reinstall php5-common, but this appears:

Package php5-common is not available, but is referred to by another  
package.  
This may mean that the package is missing, has been obsoleted, or  
is only available from another source

What am I doing wrong now? I did update apt-get after editing sources

Posted at Nginx Forum:

> **[Re: php-fastcgi always exits.. resulting in 502 bad gateway](https://forum.nginx.org/read.php?2,215576,215659#msg-215659)**
>
> Hello everyone, I'm using nginx since some days and I got a little trouble. It seems that after some while of working fine nginx exits the fastcgi-daemon and whenever I try to call a php site then, it shows me 502 Bad Gateway. Then I have to...

---

<div class="post-metadata">

**Author:** ![Lintu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@Lintu](https://www.ruby-forum.com/u/Lintu)\
**Post date:** [September 22, 2011, 11:03pm UTC](https://www.ruby-forum.com/t/php-fastcgi-always-exits-resulting-in-502-bad-gateway/212110/14 "2011-09-22T23:03:55Z")

</div>

Disregard that, I just directly downloaded the debs with wget. For the  
moment its working, thanks alot! I hope it won’t crash down every now  
and then anymore.

Thanks alot again to anyone who spent his time in this thread!

Posted at Nginx Forum:

> **[Re: php-fastcgi always exits.. resulting in 502 bad gateway](https://forum.nginx.org/read.php?2,215576,215663#msg-215663)**
>
> Hello everyone, I'm using nginx since some days and I got a little trouble. It seems that after some while of working fine nginx exits the fastcgi-daemon and whenever I try to call a php site then, it shows me 502 Bad Gateway. Then I have to...
