# 502 Bad Gateway once running php on command line

**URL:** <https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332>\
**Category:** NGINX\
**Created:** [March 23, 2016, 6:00am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332 "2016-03-23T06:00:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [March 23, 2016, 6:00am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/1 "2016-03-23T06:00:00Z")

</div>

I have just installed:

- FreeBSD 10.2
- Nginx 1.8.1
- PHP 5.5.33

Nginx works fine with PHP that the web sites seems ok to run php pages.  
However, once I run php on command line (e.g. php -v), the web site will  
get  
“502 Bad Gateway” error, and I find the nginx error log as below:

[error] 714#0: \*3 upstream prematurely closed connection while reading  
response header from  
upstream, client: _**, server: www.\_\_\_\_.com, request: “GET /  
HTTP/1.1”,  
upstream: “fastcgi://unix:/  
var/run/php5-fpm.sock:”, host: "**_"

I have tried to use either sock or port, but the problem still exist…  
any  
idea about what’s wrong? thanks.

“php -v” shows below:  
PHP 5.5.33 (cli) (built: Mar 15 2016 01:22:17)  
Copyright (c) 1997-2015 The PHP Group  
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies  
with XCache v3.2.0, Copyright (c) 2005-2014, by mOo  
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend  
Technologies  
with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo

Posted at Nginx Forum:

> **[502 Bad Gateway once running php on command line](https://forum.nginx.org/read.php?2,265576,265576#msg-265576)**
>
> I have just installed: - FreeBSD 10.2 - Nginx 1.8.1 - PHP 5.5.33 Nginx works fine with PHP that the web sites seems ok to run php pages. However, once I run php on command line (e.g. php -v), the web site will get "502 Bad Gateway" error,...

---

<div class="post-metadata">

**Author:** ![marcusy3k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@marcusy3k](https://www.ruby-forum.com/u/marcusy3k)\
**Post date:** [March 23, 2016, 7:30am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/2 "2016-03-23T07:30:33Z")

</div>

Hi,

What is the exact call you’re trying to do?

- Lucas

---

<div class="post-metadata">

**Author:** ![marcusy3k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@marcusy3k](https://www.ruby-forum.com/u/marcusy3k)\
**Post date:** [March 23, 2016, 7:36am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/3 "2016-03-23T07:36:23Z")

</div>

hi, on command line, when I type: php

or

php -v

after pressing [Enter] key, then the “502 Bad Gateway” will occur at  
once.

It is very strange, because I always think php command line should not  
affect the php-fpm…

Posted at Nginx Forum:

> **[Re: 502 Bad Gateway once running php on command line](https://forum.nginx.org/read.php?2,265576,265578#msg-265578)**
>
> I have just installed: - FreeBSD 10.2 - Nginx 1.8.1 - PHP 5.5.33 Nginx works fine with PHP that the web sites seems ok to run php pages. However, once I run php on command line (e.g. php -v), the web site will get "502 Bad Gateway" error,...

---

<div class="post-metadata">

**Author:** ![marcusy3k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@marcusy3k](https://www.ruby-forum.com/u/marcusy3k)\
**Post date:** [March 23, 2016, 10:05am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/4 "2016-03-23T10:05:21Z")

</div>

Eventually I find what went wrong, it should be caused by both Zend  
OPcache  
and XCache are installed, they may conflict each other in this case,  
once  
I’ve removed the XCache, it works fine, the php command line would no  
longer  
cause the php-fpm error.

XCache should be unnecessary when OPcache is running.

Posted at Nginx Forum:

> **[Re: 502 Bad Gateway once running php on command line](https://forum.nginx.org/read.php?2,265576,265584#msg-265584)**
>
> I have just installed: - FreeBSD 10.2 - Nginx 1.8.1 - PHP 5.5.33 Nginx works fine with PHP that the web sites seems ok to run php pages. However, once I run php on command line (e.g. php -v), the web site will get "502 Bad Gateway" error,...

---

<div class="post-metadata">

**Author:** ![marcusy3k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@marcusy3k](https://www.ruby-forum.com/u/marcusy3k)\
**Post date:** [March 23, 2016, 11:07am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/5 "2016-03-23T11:07:52Z")

</div>

yes, agree.

Thanks Lucas.

Posted at Nginx Forum:

> **[Re: 502 Bad Gateway once running php on command line](https://forum.nginx.org/read.php?2,265576,265588#msg-265588)**
>
> I have just installed: - FreeBSD 10.2 - Nginx 1.8.1 - PHP 5.5.33 Nginx works fine with PHP that the web sites seems ok to run php pages. However, once I run php on command line (e.g. php -v), the web site will get "502 Bad Gateway" error,...

---

<div class="post-metadata">

**Author:** ![marcusy3k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@marcusy3k](https://www.ruby-forum.com/u/marcusy3k)\
**Post date:** [March 23, 2016, 10:26am UTC](https://www.ruby-forum.com/t/502-bad-gateway-once-running-php-on-command-line/244332/6 "2016-03-23T10:26:23Z")

</div>

When issuing php directly from the command-line, you don’t even go  
through nginx.  
php from the command-line relies on the php-cli which isn’t talking to  
your nginx process nor php-fpm.
