Skip to content

Help: How to debug perl script from browser #2127

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

Closed
simonschaufi opened this issue Dec 8, 2019 · 5 comments
Closed

Help: How to debug perl script from browser #2127

simonschaufi opened this issue Dec 8, 2019 · 5 comments
Labels

Comments

@simonschaufi
Copy link

simonschaufi commented Dec 8, 2019

  • IDE: Phpstorm 2019.3
  • Perl5 plugin version: 2019.3
  • JRE version: openjdk version "1.8.0_222"
  • Ubuntu 18 LTS
  • Also installed Devel-Camelcadedb with sudo cpan Devel::Camelcadedb

I browsed through the wiki (https://github.com/Camelcade/Perl5-IDEA/wiki/Perl-Debugger) and all the issues that are related to debugging and couldn't find anything helpful on how to setup browser debugging. Debugging within the IDE works fine but I have no idea how to configure my system in order to call http://localhost/cgi-bin/test.cgi and debug the test script which looks like this:

#!/usr/bin/perl
print "content-type: text/html\n\n";
print "Hi";
exit;

I use nginx with fcgiwrap and the following config:

server {
    ...

    location /cgi-bin/ {
        gzip off;

        fastcgi_pass unix:/var/run/fcgiwrap.socket;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    ...
}

The script is executed without problems and I can see "Hi" in my browser.

What do I need to do in order to debug this script when called from the browser? This is just a test script but later on I want to debug a whole perl application.

@simonschaufi simonschaufi changed the title Debug perl script from browser Help: How to debug perl script from browser Dec 8, 2019
@hurricup
Copy link
Collaborator

hurricup commented Dec 9, 2019

There is no high-level way to debug a scripts opened in browser. You should configure remote debugging for that manually.

@simonschaufi
Copy link
Author

I tried the remote debugging but still don't really know how to configure everything. PhpStorm listens on 0.0.0.0:12345 but now I'm stuck.

@hurricup
Copy link
Collaborator

hurricup commented Dec 9, 2019

Probably this issue will help #1771

@simonschaufi
Copy link
Author

simonschaufi commented Dec 11, 2019

@hurricup I got it working! Finally! 🎉

Let me document it here even though the wiki would be a better place.

Setup IDE like this:

  1. Add remote debugger with server host: 127.0.0.1 and port 12345 (can be any number where the port is still available)
  2. Change Shebang line to #!/usr/bin/perl -d:Camelcadedb in the script you want to debug

Setup nginx like this (port must match with IDE port):

server {
    listen 80;
    server_name .example.test;
    root "/home/username/Code/example.test";

    index index.html;

    charset utf-8;

    location / {
        index index.html;
    }

    location /cgi-bin/ {
        gzip off;

        fastcgi_pass unix:/var/run/fcgiwrap.socket;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PERL5_DEBUG_ROLE "client";
        fastcgi_param PERL5_DEBUG_HOST "127.0.0.1";
        fastcgi_param PERL5_DEBUG_PORT "12345";
        charset iso-8859-1;
    }

    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  /var/log/nginx/example.test-error.log error;

    sendfile off;
}

Then click "Debug..." in IDE in order to start listening and then open the perl script in the browser.

The key for me was not to set the environment variables in my home directory but right in the browser config and then change the Shebang.

Problem solved!

@hurricup
Copy link
Collaborator

referenced in documentation. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants