beyondcode / herd-community

80 stars 1 forks source link

[Bug]: Have to reset xdebug server daily in PhpStorm (Herd Pro) #778

Closed wesleylether closed 1 month ago

wesleylether commented 3 months ago

Platform

macOS

Operating system version

macOs Sonoma 14.0 (23A344)

System architecture

ARM64 (M1, M2, etc)

Herd Version

1.6.1 (Build: 25)

PHP Version

PHP 8.3.7 (cli) (built: May 10 2024 12:47:16) (NTS)

Bug description

Hi Beyond code,

When I listen to debug connections and create a request with the website, the popup in PhpStorm opens and when I select the project, the xdebug connection works properly. But after I close the project in PhpStorm, I have to remove the server in PhpStorm settings PHP > Servers and restart the connection again. And then it works again.

Steps to reproduce

  1. Create a Xdebug connection with PhpStorm
  2. Create a breakpoint in the project
  3. Validate breakpoint is working
  4. Close project in PhpStorm
  5. Reopen project in PhpStorm
  6. Try to hit the breakpoint again

Relevant log output

No response

mpociot commented 3 months ago

I'm unable to reproduce this. When I re-open my project, the breakpoint can immediately be triggered. This sounds like it's a PHPStorm issue rather than a Herd issue though.

Could you try and run phpinfo() to ensure that the xdebug extension is always loaded?

wesleylether commented 3 months ago

Hi Marcel,

The test shows no difference in the PHP configuration. xdebug is always loaded 🤔

mpociot commented 3 months ago

Then it sounds even more like a PHPStorm issue to me as that's all that we manage in Herd, so PHPStorm should be able to connect. You can report a bug via PHPStorm (Help / Submit a bug report)

image
wesleylether commented 2 months ago

Hi @mpociot,

I have done a clean installation of PhpStorm without any plugins or configurations. Also, a clean installation of Herd Pro, but the problem continues to occur?

What could else be a problem? Because it is slowly becoming an irritation at my daily workflow!

Any help or pointing in a direction would be appreciated.

wesleylether commented 1 month ago

@mpociot I have created a ticket at JetBrains for this issue. But when they researched the logs, they have found the problem that the sites on Herd configuration doesn't have a server name?

See discussion: https://youtrack.jetbrains.com/issue/WI-77783

This issue I have reported a long time ago, that Herd does not create a server name for its sites. Or does it have to do, but on my machine it won't? I don't know. But I would appreciate it if this is continued to be researched, so the issue can be resolved.

Awaiting your response.

mpociot commented 1 month ago

@wesleylether According to JetBrains, Herd is not properly sending the SERVER_NAME which works fine for me though. And it also works for you the first time until you close the PHPStorm project, right? So I don't see any reason why Herd should no longer send the SERVER_NAME as soon as you close the PHPStorm project - as this is pretty unrelated to me.

Can you confirm that when you simply do a var_dump($_SERVER["SERVER_NAME"]); that this is empty for you?

We explicitly specify this in the nginx configuration.

wesleylether commented 1 month ago

@mpociot this is indeed empty for me!

mpociot commented 1 month ago

Interesting!

If you open up this file: ~/Library/Application Support/Herd/config/nginx/herd.conf it should say:

fastcgi_param SERVER_NAME  $host;

Can you confirm this? If that's not the case for you, please adjust the configuration file and then stop/restart the Herd services.

wesleylether commented 1 month ago

For me that is: fastcgi_param SERVER_NAME $server_name;

wesleylether commented 1 month ago

I also checked the values in /Applications/Herd.app/Contents/Resources/config/nginx/herd.conf But here also is it with $server_name defined! 🤔

wesleylether commented 1 month ago

I have version 1.9.1 (build: 31)

mpociot commented 1 month ago

Hm yeah I see that most Valet drivers seem to set the host name themselves.

Does it work for you if you modify the config though?

wesleylether commented 1 month ago

Can you show what your herd.conf file looks like? Maybe there are more options needed to change? And why is this configuration different for me?

mpociot commented 1 month ago
server {
    listen 127.0.0.1:80 default_server;
    #listen VALET_LOOPBACK:80; # valet loopback
    root /;
    charset utf-8;
    client_max_body_size 1024M;

    location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
        internal;
        alias /;
        try_files $uri $uri/;
    }

    location / {
        rewrite ^ "/Applications/Herd.app/Contents/Resources/valet/server.php" last;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log "/Users/marcelpociot/Library/Application Support/Herd/Log/nginx-error.log";

    error_page 404 "/Applications/Herd.app/Contents/Resources/valet/server.php";

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $herd_sock;
        fastcgi_index "/Applications/Herd.app/Contents/Resources/valet/server.php";
        fastcgi_param QUERY_STRING  $query_string;
        fastcgi_param REQUEST_METHOD  $request_method;
        fastcgi_param CONTENT_TYPE  $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param SCRIPT_FILENAME  $request_filename;
        fastcgi_param SCRIPT_NAME  $fastcgi_script_name;
        fastcgi_param REQUEST_URI  $request_uri;
        fastcgi_param DOCUMENT_URI  $document_uri;
        fastcgi_param DOCUMENT_ROOT  $document_root;
        fastcgi_param SERVER_PROTOCOL  $server_protocol;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE  nginx/$nginx_version;
        fastcgi_param REMOTE_ADDR  $remote_addr;
        fastcgi_param REMOTE_PORT  $remote_port;
        fastcgi_param SERVER_ADDR  $server_addr;
        fastcgi_param SERVER_PORT  $server_port;
        fastcgi_param SERVER_NAME  $host;
        fastcgi_param HTTPS   $https if_not_empty;
        fastcgi_param HERD_HOME "/Users/marcelpociot/Library/Application Support/Herd";
        fastcgi_param REDIRECT_STATUS  200;
        fastcgi_param HTTP_PROXY  "";
        fastcgi_buffer_size 512k;
        fastcgi_buffers 16 512k;
        fastcgi_param SCRIPT_FILENAME "/Applications/Herd.app/Contents/Resources/valet/server.php";
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}

I'll check this again with the base Valet package, as they also user $server_name instead of $host - maybe this was a manual change that I did at some point in my local file 🤔

Anyway, adding this change will make the SERVER_NAME be properly set again 👍 I'll look at the default configuration for this so it doesn't affect new installations.

wesleylether commented 1 month ago

@mpociot setting it to $host does do the trick! Checked the rest of the configuration and those are all the same. Finally, this is working like a charm! Thanks for your time to fix this issue