Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

502 Bad Gateway Nginx Mac OS X Yosemite php56 php-fpm

I was Brew’ing PHP, MySQL & Nginx on Mac OS X, but I can't make this work.

Any idea what I'm doing wrong?

phpinfo is working

/log/nginx/access.log

127.0.0.1 - - [14/Mar/2015:21:21:16 -0500] "GET /wp/wp-admin/install.php HTTP/1.1" 502 574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2331.4 Safari/537.36"

/log/virtualhost/error.log

2015/03/14 21:21:16 [error] 82682#0: *59 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /wp/wp-admin/install.php HTTP/1.1", upstream: "fastcgi://unix:/usr/local/var/run/php-fpm/php-fpm.sock:", host: "localhost"

/log/php-fpm.log

[14-Mar-2015 21:21:16] WARNING: [pool www] child 6851 exited on signal 11 (SIGSEGV) after 11147.271614 seconds from start
[14-Mar-2015 21:21:16] NOTICE: [pool www] child 82712 started

My Nginx conf /usr/local/etc/nginx/nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include sites-enabled/*.conf;
}

My Nginx virtual server conf /usr/local/etc/nginx/sites-available/local.conf

server {
  listen                *:80;
  server_name           localhost;
  error_log            /log/virtualhost/error.log;
  root                 /server;
  location / {
    try_files  $uri  $uri/  /index.php?$args;
    index index.php;
  }
  location ~ \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    unix:/usr/local/var/run/php-fpm/php-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
  }
}

My php-fpm conf /usr/local/etc/php/5.6/php-fpm.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
;user = _www
;group = _www
listen = /usr/local/var/run/php-fpm/php-fpm.sock
like image 905
Mao8a Avatar asked Mar 15 '15 04:03

Mao8a


3 Answers

I had this problem and solved it by recompiling php with different options:

brew uninstall php56 && brew install php56 --with-debug --without-apache

Seems to be something that went wrong with the original build, maybe those flags or maybe with the tool chain. I seem to remember it complained about not having xcode cli tools the first time round, then installing them and running the build again. Either way, that worked for me.

SIGSEGV in your FPM log means "segmentation fault", which is something wrong in the err.... guts of PHP I think, not a config thing... Sure someone more intelligent can expand on that ;-)

like image 115
BaronVonKaneHoffen Avatar answered Oct 20 '22 07:10

BaronVonKaneHoffen


I had a lot of dead-ends trying to figure this out. After trying BaronVonKaneHoffen's solution, still no beans. I read in the Homebrew documentation after reinstalling:

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

PATH="/usr/local/sbin:$PATH"

The OSX native php-fpm was running, not the one packaged from homebrew.

I edited the $PATH file by writing the .bash_profile script as follows:

In terminal:

cd
touch .bash_profile
nano .bash_profile

Then write in the file:

export PATH=/usr/local/sbin:${PATH}

and save.

Restart and see if that helps!

like image 28
Cliff Avatar answered Oct 20 '22 06:10

Cliff


I've solved this problem, the reason is php process have not write permission for session file path, so the solution is:

  1. edit /usr/local/etc/php/5.6/php.ini and give session.save_path a writable directory;
  2. /usr/local/opt/php56/sbin/php56-fpm reload;
like image 20
Amom Avatar answered Oct 20 '22 06:10

Amom