Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Troubleshooting] PHP 8.1 site with Xdebug causes Bad Gateway error #279

Closed
1 task done
incon opened this issue Feb 22, 2024 · 24 comments
Closed
1 task done

[Troubleshooting] PHP 8.1 site with Xdebug causes Bad Gateway error #279

incon opened this issue Feb 22, 2024 · 24 comments
Assignees
Labels
troubleshooting Trying to figure out what went wrong.

Comments

@incon
Copy link

incon commented Feb 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

502 Bad Gateway

Expected Behavior

Turning on Xdebug makes every request return a 502 Bad Gateway error

Steps To Reproduce

Turn on Xdebug and try to debug.

Environment

- macOS: 14.3.1
- Valet: 4.6.1
- PHP Monitor: 7.0.1

Do you have a log file (or a screenshot) or any additional information?

No response

@incon incon added the bug Something isn't working (correctly). label Feb 22, 2024
@nicoverbruggen
Copy link
Owner

Hmm... Bad gateway errors are usually resolved by restarting nginx and PHP.

Can you restart the Valet services via the menu item and let me know if that solved the issue? (You can also try "Fix My Valet", actually)

If neither works, can you let me know the output of php -v?

@incon
Copy link
Author

incon commented Feb 22, 2024

PHP 8.1.27 (cli) (built: Dec 19 2023 20:35:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies

@incon
Copy link
Author

incon commented Feb 22, 2024

Works fine if I switch to PHP 8.3 but I run this project on PHP 8.1 in production and I would like my local and production versions match.

@incon
Copy link
Author

incon commented Feb 22, 2024

When Xdebug is on

PHP 8.1.27 (cli) (built: Dec 19 2023 20:35:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

@nicoverbruggen
Copy link
Owner

So this is only happening with PHP 8.1, correct?

And you installed xdebug via the extension manager for that PHP version?

@nicoverbruggen
Copy link
Owner

With gateway errors you can probably find more information by checking the output of ~/.config/valet/Log/php-fpm.log.

Try running cat ~/.config/valet/Log/php-fpm.log and let me know what's in there. It probably contains a bunch of warnings there.

@nicoverbruggen nicoverbruggen changed the title [Bug] PHP 8.1 site with Xdebug [Troubleshooting] PHP 8.1 site with Xdebug causes Bad Gateway error Feb 22, 2024
@nicoverbruggen nicoverbruggen added troubleshooting Trying to figure out what went wrong. and removed bug Something isn't working (correctly). labels Feb 22, 2024
@incon
Copy link
Author

incon commented Feb 22, 2024

2024/02/22 17:58:12 [error] 94673#0: *13 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server:

@incon
Copy link
Author

incon commented Feb 22, 2024

So this is only happening with PHP 8.1, correct?

And you installed xdebug via the extension manager for that PHP version?

Yes and I have tried installing the extension via the manager.

@nicoverbruggen
Copy link
Owner

Ah, the dreaded premature closed connection w/o much context.

  1. Are your PHP versions up-to-date (you can check via the PHP version manager)? If not, you may be dealing with an outdated version of PHP 8.1, which isn't compatible with the binaries of PHP 8.1's xdebug that were installed via the extension manager... you can try updating/upgrading.

  2. Alternatively, it may be related to this issue, in which case you can try this workaround but if you are on a recent version of Valet (and it seems you are) it may be enough to simply run valet install again.

@incon
Copy link
Author

incon commented Feb 22, 2024

Everything is up to date and I've tried valet install

@nicoverbruggen
Copy link
Owner

Can you try the workaround I've linked?

@incon
Copy link
Author

incon commented Feb 22, 2024

Tried

;Signal 11 workaround
env['PGGSSENCMODE'] = disable
env['LC_ALL'] = C

Didn't work

Tried deleting the sock and installing Valet again didn't work.

@incon
Copy link
Author

incon commented Feb 22, 2024

If I disable Xdebug everything works the issue is only when Xdebug is loaded.

@nicoverbruggen
Copy link
Owner

@incon I meant this workaround, updating the plist file. (The PGGSSENCMODE workaround is specific to PostgreSQL and is probably not the cause here.)

Give that a try! When you installed Xdebug, was PHP 8.1 the globally linked PHP version, or not? If the workaround doesn't work I want to see if I can reproduce this issue on my own system.

@incon
Copy link
Author

incon commented Feb 22, 2024

I noticed PGGSSENCMODE was already included.

I've tried to remove everything and set everything up again

Removed brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Removed items not removed by brew uninstall
sudo rm -rf /opt/homebrew

Removed Valet config
rm -rf ~/.config/valet/

Removed global composer
rm -rf ~/.composer/

Reinstall brew

brew install [email protected]
brew install composer // installed php 8.3
composer global require laravel/valet
valet install
brew tap shivammathur/extensions

Launched phpmon
Open View Domains List and set the project I want to be in PHP 8.1
Install Xdebug via the extension ui.
Configure 20-xdebug.ini with

xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.start_upon_error=yes

502 Bad Gateway

@incon
Copy link
Author

incon commented Feb 22, 2024

Switch the site to PHP 8.3 and install extension via ui, configure Xdebug and it works correctly.

@incon
Copy link
Author

incon commented Feb 22, 2024

Issue is only when in isolation mode or not set on PHP 8.3

@nicoverbruggen
Copy link
Owner

I'm trying to reproduce this issue and unfortunately this seems to work correctly here. I've made sure to try both PHP 8.1 linked and isolated (with PHP 8.3 as the primary version and using site isolation). As you can see:

image

What kind of project are you trying to use with Valet?

Can you try a simple site? Here's a basic test, that's the one I just did:

  1. Make a new folder and set it to use PHP 8.1 (via View Domains List...) -> I used phpinfo as the folder name
  2. Create index.php
  3. Add phpinfo() (see below)
  4. Navigate to the folder name .test (in my case: phpinfo.test)
<?php

phpinfo();

Does that work? Or are you also getting an error this way? It's always possible that your PHP script itself causes the issue.

It's worth checking the nginx log too... cat ~/.config/valet/Log/nginx.log -- maybe there's something useful in there.

@incon
Copy link
Author

incon commented Feb 22, 2024

Only when Xdeug is connected to a debuger is when I get the issue.

@nicoverbruggen
Copy link
Owner

Ah, I see.

This may very well be a Xdebug or configuration issue that I'm not familiar with... from what I can tell, the app has correctly installed the extension.

How are you debugging with Xdebug? What IDE? What browser? I'll see if I can't repro it on my end.

@incon
Copy link
Author

incon commented Feb 22, 2024

Tested a phpinfo.test and it worked with debuging turn on.

@incon
Copy link
Author

incon commented Feb 22, 2024

I just tried a blank Laravel project and it worked also.

@incon
Copy link
Author

incon commented Feb 22, 2024

I've tried PHPStorm my normal editor and VS Code with the Xdebug plugin.

@nicoverbruggen
Copy link
Owner

Hmm... in that case I don't think I can help you any further, as it's likely an issue with that specific site or project, right?

At the very least, I'm going to move this topic to Discussions, should anyone bump into a similar problem they can find this thread there under the troubleshooting section.

Repository owner locked and limited conversation to collaborators Feb 22, 2024
@nicoverbruggen nicoverbruggen converted this issue into discussion #280 Feb 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
troubleshooting Trying to figure out what went wrong.
Projects
None yet
Development

No branches or pull requests

2 participants