Xdebug can not connect to PhpStorm on OS X Mavericks

Dear all,

after three days of unsuccessful efforts I have no idea, why I can't get Xdebug to work with PhpStorm on Mac OS. I already set up PhpStorm and Xdebug on a Windows 8 machine succesfully.

OS: Mac OS X 10.9.2 Mavericks
IDE: PhpStorm 7.1.3
Firewall: disabled
OS: CentOS release 6.3 (Final)
PHP: PHP Version 5.3.3 with Xdebug v2.2.4
Firewall: disabled

In the Preferences » Project Settings » PHP » Debug I configured the Xdebug Port as 9002 and selected...

  • Can accept external connections
  • Force break at first line when no path mapping specified and
  • Force break at first line when script is outside the project.

In the Preferences » Project Settings » PHP » Servers when I press the Validate remote environment button and click Validate everything seems to be correct:

  • Loaded php.ini: /etc/php.ini
  • Loaded: Xdebug 2.2.4
  • Remote host: client ip
  • Remote mode 'req' is enabled (the debug session will be initiated on script start)

By navigating to Run » Debug Configurations I added a PHP Remote Debug configuration that uses my server and the Ide key PHPSTORM

When I start Debugging the hint appears Waiting for incoming connection with ide key 'PHPSTORM'. I added a breakpoint and also added a call to xdebug_break().

But when I open the browser and navigate to my site and passing the parameter XDEBUG_SESSION_START=PHPSTORM the execution does not stop there.

I tried to connect via telnet and that seems to work:

telnet -e p 192.168.2.xxx 9002
Telnet escape character is 'p'.
Trying 192.168.2.xxx...
Connected to 192.168.2.xxx.
Escape character is 'p'.
telnet> quit
Connection closed.

The xdebug.remote_log lists connection problems:

Log opened at 2014-04-21 19:24:25
I: Connecting to configured address/port: 192.168.2.xxx:9002.
E: Could not connect to client. :-(
Log closed at 2014-04-21 19:24:25

Because of the log entries I am sure, that Xdebug is working and tries to connect to PhpStorm. My tests using telnet and the PhpStorm build in validation did work. Both firewalls are disabled. So what could be the problem?

A big thank to everybody who read these lines and thought about it. It would be great, if anyone had an idea what I could have missed.


I just tried debugging from cli and that worked! PhpStorm came to top and stopped the execution of the program. How is that possible?


Log opened at 2014-04-21 20:36:11
I: Connecting to configured address/port: 192.168.2.xxx:9002.
I: Connected to client. :-)

Debugging by using the browser still doesn't work :(

Comment actions Permalink

First of all I can recommend you to use Zero-configuration debugging: http://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm .

Anyway, please check that you're using correct php.ini.

Comment actions Permalink

Dear Liubov,

thank you very much for your advice. Both the ouput of phpinfo(); opened in my browser and the output in the command line declare the use of the file /etc/php.ini.

# php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc

Loaded Configuration File => /etc/php.ini

Nevertheless the execution is only interrupted when I start a php script from the command line and not by navigating to a php file using the browser. In both cases Xdebug tries to connect to the client - same IP, same port - one time successfully and failing the other time.

This is also the case when I use the Start Listen for PHP Debug Connections button mentioned on the site you referred to. The only difference I see is, that my server is not on localhost but on a remote machine.

Comment actions Permalink

Please check that in PHP | Debug option "Ignore external connections *"is disabled.
Also if you already have a server in PHP | Servers, please check it, if not - please create it.

Comment actions Permalink

Thank you again for your ideas.

In the Preferences » Project Settings » PHP » Debug the checkbox Ignore external connections through unregistered server configurations is not ticked.
In the Preferences » Project Settings » PHP » Servers the remote server is configured with its IP, port 80, Debugger Xdebug.
The Validation of the remote environment is successful.

Comment actions Permalink

Please try this:
create the empty project with one file, remove all servers from Settings | PHP | Servers, then check again $_SERVER["REMOTE_ADDR"], $_SERVER["SERVER_NAME"], xdebug.remote_port and try to reproduce the issue.

Comment actions Permalink

I had similar problem. My environment should be simpler as I run everything on my centos 6.3.

  • centos 6.3
  • phpstorm 7.1.3
  • xdebugger 2.2.5
  • idekey STORM in both /etc/php.ini and phpstorem setting.
  • remote port is 10000 in both /etc/php.ini and phpstorm xdebug cfg
  • protocol: DBGp
  • drupal 7.28 + mysql
  • my drupal module project is in my home dir; my drupal root is on /var/www/html.
  • set breakpoints on my module file, index.php, and includes/boostrap.inc
  • SERVER_NAME  localhost
  • SERVER_ADDR  ::1
  • REMOTE_ADDR  ::1
  • xdebug.remote_port 10000

xdebug remote log shows:

Log opened at 2014-07-15 05:18:54

I: Connecting to configured address/port: localhost:10000.

E: Could not connect to client. :-(

Log closed at 2014-07-15 05:18:54

However I can telnet to localhost:10000.
[handongw@torlx-handongw www]$ telnet -e p localhost 10000
Telnet escape character is 'p'.
Trying ::1...
telnet: connect to address ::1: Connection refused
Connected to localhost.
Escape character is 'p'.

telnet> quit
Connection closed.

Comment actions Permalink

I had similar issue on CentOS 6.3. I debugged it and found the root cause.

the root cause is that Centos 6.3 does not allow httpd to make tcp connection by default.
I need to run sudo setsebool -P httpd_can_network_connect=1 to get it work!

still xdebugger should put more detailed messages should error happened.

the piece of code the failed to connect is:


status = connect(sockfd, (struct sockaddr*)&address, sizeof(address)); failed.

the errno is "Permission denied".

Comment actions Permalink

thanks for sharing!

Comment actions Permalink

When I went to developing on a MAC from Windows, I think I had the same problem as you.
I could set breakpoints in other files on Windows and PHPStorm would break as expected in the IDE.
When I moved to the MAC the breakpoints stopped working.

I fixed this writing my own using my own classloader:



// class Loader
    static function classLoader($c)
        $filename = '\\' . $c . '.php';
        $file = str_replace('\\', DIRECTORY_SEPARATOR, $c) . ".php";

        if (!file_exists($file))
            return false;

        require_once $file;

// register the loader functions
spl_autoload_register(array ('Loader', 'classLoader'));

If you are using name spaces and put things in seperate directorires, they will not resolve in PHPStorm.  On windows the direrctory seperator is '\'
on a MAC it is '/'.  When I looked at the use statement was being resolved, that was the case.
I have since frameworksm doing this in their frameworks.

After doing this I can debug fine PHPStorm on Windows or MAC.  This is in the PHPStorm Bug Tracker, WI-24944 and is open as a bug.
Not really sure what can be done.  When you use PHPStorm as the tool it is, at some point it is at the mercy of PHP the language.

Case in point is the dreaded PHP function Extract which takes items from assoc. array and injects them into the local PHP stack frame.
Of course things like @var can help.  But remember that PHP is a dynamic language.

Comment actions Permalink

Hi. I have the same problem with PhpStorm 2017.2 and macOS Sierra 10.12.6 apache server, and the same with Vagrant server too.

Any ideas how to solve this problem?

Comment actions Permalink

> Any ideas how to solve this problem?

The most common issue on macOS is that php-fpm occupies port 9000 so PhpStorm can't listen to it, and thus debugging doesn't work.
Please enable Xdebug remote logging, try to start a remote session, collect and upload the log somewhere.

Comment actions Permalink

I was also getting Waiting for incoming connection with ide key 'PHPSTORM' and changing the debug port from 9000 to 9002 worked for me.

Comment actions Permalink

+1 for me on mac sierra port 9000 was causing the issue even with debug validator was fine. Lost a lot of time. Just switch to another port.


Please sign in to leave a comment.