Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

502 Bad Gateway when debugging php 7 Xdebug 2.4.0RC3 mac os

I'm using the latest versions of PHP (7.0.2) and xdebug (2.4.0RC3) with phpstorm 9.0.2 and when I start debugging I immediately get the

error "502 Bad Gateway"

Sometimes I manage to step through a few lines of code but then I get the error anyway.

When I had previous versions of PHP (5.6) and xdebug everything was great.

P.S. php, nginx and xdebug are installed with homebrew.

like image 573
Alex Vasilev Avatar asked Jan 11 '16 12:01

Alex Vasilev


1 Answers

You can try this: open your php.ini, sorry I don't know where it's placed in MacOS, in Ubuntu it is on

/etc/php/7.0/fpm/php.ini

open it with your favourite text editor with needed privileges to save config files. Goto xdebug section and check if you've set it up correctly. In my case it looks like down below. Note that path to xdebug.so in your case could be different.

[Xdebug]
zend_extension="/usr/lib/php/20151012/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="\tmp"
xdebug.idekey="PHPSTORM"
xdebug.remote_autostart=1
xdebug.remote_host=192.168.10.10
xdebug.remote_mode=req
xdebug.remote_connect_back=1
xdebug.max_nesting_level=200
xdebug.var_display_max_depth=1000
xdebug.var_display_max_children=256
xdebug.var_display_max_data=4096

;this line below to prevent debug stop timeout
request_terminate_timeout=600s

Another thing to check in php.ini is

max_execution_time = 600

I've set it in seconds as above to prevent stopping debugging session by default it's set to 30 sec

Next thing you need to check is nginx configuration I've added to main nginx.conf http section those lines

http {

    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    fastcgi_read_timeout 600s;
    proxy_read_timeout 600s;
    fastcgi_buffers 8 16k;
    fastcgi_send_timeout 600s;
    fastcgi_buffer_size 32k;

   #other standard settings below...

I've added them to give me more time for debugging session so it will not be stopped in 600sec.

After all editing. Restart php7.0-fpm and nginx. I'm not sure how it's done in MacOS in Ubuntu it is done through:

 sudo service php7.0-fpm reload
 sudo service php7.0-fpm restart
 sudo service nginx reload
 sudo service nginx restart

Maybe it's overkill to reload and then restart but to be insured :)

Also take a look at your error.log files for nginx In Ubuntu they are placed in /var/logs/nginx/ there is error.yourdomain.log go to the last lines and see what has happened. Hope it'll helps.

UPD: For anyone who will use Homestead with ngrok tunnel (or for example ssh -R 3000:localhost:8000 [email protected] and then on public site you'll setup nginx as a reverse proxy for somedomain on port 80 to read from 3000 tunneled via SSH) to expose local development to internet.

To enable debugging you need to comment out line xdebug.remote_connect_back=1 or set it's value to 0. Otherwise xdebug will get X-Forwarded-For and other headers and will try to connect back to nginx but not to your local dev, and debugging will not start.

like image 85
Mikhail.root Avatar answered Nov 12 '22 12:11

Mikhail.root