How to debug PHP application

Hi,

How do I debug a PHP app? I press RUN and it loads apache and everything works, but nothing works in the debugger itself. Tried to put variables in watch, etc

1 Like

Hi,

Did you use a breakpoint to stop the execution of your application? If so, can you confirm if your code is entering the place where the breakpoint was positioned? Also, please confirm that the debugger is activated: you can see that it is by the green bug button on the run panel.

Regards,
​Mutahhir

I don’t know what happened, but I can’t use debug with PHP anymore… :cry: Every time it uses “shell command” and of course it crashes. I can’t find “php” option in the run menu.

What’s really strange is that it worked a few weeks ago!

I even remove and reinstall php5-xdebug package, but nothing works.

Any hints.

Thanks!

Hi,

In order to use PHP, please select the Apache httpd (PHP + HTML) runner from the runners dropdown list.

Can you let me know if this resolves the issue?

Regards,
​Mutahhir

Hi,

Thanks for your answer.
Unfortunatelly, there is the issue… The entry does not appear in the list… :sweat:

Antoine

On which workspsace do you see that?

both apache php and php web server should work

1 Like

Hi
I added a breakpoint, but the application runs as regular. It does not stop at the breakpoint (I tried lines which it executes for sure).
Run->Show debugger at Break is enabled

you need to toggle debugging on by clicking on the grey bug shaped button near the runner name

1 Like

Also note that the file won’t run until you actually access it on the server by going to the URL where it’s hosted. Otherwise, the server will start but the file will never run because it’s just sitting there waiting to be served. Once you access the page, it will hit the breakpoint.

I got it to work, but its still inconsistent. A lot of times I have to stop the server and restart, or reload the whole environment. Usually it stops on the first time in the breakpoint but not in the next times I access the page

Thank you for following up about this. Can you record a screencast so I can see exactly what’s going on? Then we can look into making the whole experience much more clear.

Hello,

I am facing the same problems - mentioned in this thread - with debugging in cloud9. If you are willing to contact me, I would love to have a skype call about the debugger.

Kr,

Gregor

Is there a solution for that problem? I have exectly the same issue. Sometimes the debugger is working sometimes not.

Hello,
I am also having a problem getting php debugging to work.

The application runs fine with debugging off, but when I try with debugging (Stop server; click to make the bug icon green; start server)
I reload the same page that worked and get the ‘No application seems to be running’ page.

I’ve tried this with both the apache and the php server .

Any ideas on what I can do?

Thanks,
-Chris

2 Likes

I solved this problem by uninstalling php-xdebug with --purge, then I reinstalled it via PECL following these instructions: https://xdebug.org/docs/install#configure-php

pecl install xdebug
You still need to add the correct line to your php.ini: (don’t forget to change the path and filename to the correct one — make sure you use the full path)

zend_extension="/usr/local/php/modules/xdebug.so" <= you need this line

Note: You should ignore any prompts to add “extension=xdebug.so” to php.ini <= you DON’T need this line. If you find it in config files, remove it or comment ir.

Is the only way to debug a PHP application to use a “runner”? Typically, you can configure an editor to listen for connections from the server to invoke the debugger.

The reason I ask is I’m using the SSH connection, so I’m not sure a runner will help… Namely, I’d have to configure the runner to match the apache setup already configured on my remote server? That sounds like a real chore / rather error prone!

You can create a runner that does nothing or tails a log file https://github.com/c9/core/issues/236#issuecomment-172935667

{
    "cmd": [ "sleep",  "20000" ],
    "selector": "^.*\\.(php|phar)$",
    "info": "Running PHP script $file",
    "working_dir": "$project_path",
    "debugger": "xdebug",
    "debugport": 9000
}

when running it the ide will try to connect to existing xdebug session which was launched by some other way

ok thanks, I will try it and let you know! and let me say, thank you for the quick reply!

Hi @harutyun I’m finally trying this out and not having much luck :frowning:

I created a custom runner as you suggested, installed xdebug and have this xdebug config

zend_extension=xdebug.so

xdebug.max_nesting_level=250
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_connect_back=On
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.overload_var_dump=0

I start the runner up, then if I put a breakpoint in index.php of my application, I am able to invoke th eC9 debugger if I use lynx http://localhost, however the “step into”, “step over” etc buttons are disabled.

I found in that link you shared there is debughost option, which I have added to my custom runner:

"debughost": "0.0.0.0"

When I start the runner with this added config, on the shell I check for running processes and I can see it’s working (presumably)

$ sudo netstat -ant | grep -i listen   
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN  

However, when I hit my site from my local machine (over the internet) the debugger is not invoked in the C9 editor, so something still isn’t working. To summarize the outstanding issues I’m facing are:

  • step into / step over etc not working
  • unable to invoke editor when accessing php page from laptop

Wow, ok, making some headway…

I enabled xdebug.remote_log and looked at the log. Seems xdebug could not connect to the client, which I presume in this case is the runner, right? xdebug however was trying to connect to the real client (my laptop) in this case 192.168.88.23; so here’s the magic touch, instead of xdebug.remote_connect_back=On I now have xdebug.remote_host=localhost read: “connect to the custom runner”… This is working, and a debug session is starting in the C9 editor, when I hit the site from y laptop. Great stuff BUT the step into / step over etc buttons are still disabled :sob: Any idea why?

EDIT
Restarted the editor… debugger is WORKING. Only strange thing left is the run dialog seems to be disconnected from the actual process. For example right now, the tab says “Running” yet there is a “Run” button (instead of a “Stop” button)

What’s more after restarting the editor, I can see there is a runner process via this CLI command: ps ax | grep xdebug. Killing it manually on the CLI only saw a fresh process return in its place. I did a full reboot of the machine and now the runner tab also seems to work as expected.

Long story short - do not use xdebug.remote_connect_back=On, use xdebug.remote_host=localhost