Setting up Remote Debugging with PHP Storm

Many occasions you’ll encounter that the frontend resides on a different server than where the backend code is. Or you may be making a CURL request to a remote server. In such situations – the PHP Storm Debugger or the Browser may not be able to get debug information for the remote server.

Solution: Create a proxy server on the remote server. Link the proxy server to the local debugger and the client on your desktop. Now – the proxy intermediates between your requests and the response from the server and thereby you are able to set breakpoints and debug code executing on the backend server.

Steps to follow

1. Refer to configuration settings on http://matthardy.net/blog/configuring-phpstorm-xdebug-dbgp-proxy-settings-remote-debugging-multiple-users/

2. Install Python Library for Proxy setup on the remote server. Use Komodo Python Remote Debugging Client – http://code.activestate.com/komodo/remotedebugging/

3. Install xdebug on the remote server (xdebug.so)

4. Modify the php.ini file under /etc/php5/apache2 and add the following lines:

; Enable Xdebug
zend_extension="/opt/xdebug/xdebug-2.1.4/modules/xdebug.so"
xdebug.remote_enable=1
xdebug.idekey="MY_OWN_XDEBUG_KEY"
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log="/tmp/xdebug.log"

5. Create a batch file with the following lines of code to execute the python proxy server:

#!/bin/bash -f
cd /usr/local/src/Komodo-PythonRemoteDebugging-7.1.2-73175-linux-x86/bin
#while [ $? == 1 ]
while true;  do
  echo Starting pydbgpproxy at `date`
  ./pydbgpproxy -i 0.0.0.0:9001 -d 9000
done

9001 is the client port and 9000 is the local port. The above line translates to redirecting all traffic from port 9001 to port 9000.

6. Restart Apache2 Server

7. Modify the client port on the PHP Storm IDE. Settings > PHP > Debug > XDebug > Debug Port – Set to 9001

8. Click on the icon that looks like a phone to start listening to incoming traffic on port 9001.

9. Modify DBGp configuration on PHP Storm. Tools > DBGp Proxy > Configuration

IDE_KEY: MY_OWN_XDEBUG_KEY

Host: IP Address of the Remote Server

Port: 9001

10. Register the IDE. Tools > DBGp Proxy > Register IDE. A successful message is shown on the screen.

11. Restart PHP Storm

12. Setup Debug Configuration and Directory Mappings for your project in PHP Storm

13. When a CURL call is made to the remote server, modify the call to include this paramter in the URL:

?XDEBUG_SESSION_START=MY_OWN_XDEBUG_KEY

14. Add Frontend and Backend server sto the XDebug settings on your Chrome browser

15. NOTE: Do Not select the debuggin options on the browser when trying to debug the remote server.

16. Start the Debugger for the project. Activate remote listening using the phone icon. Register the IDE, add Breakpoint in the code on the remote server.

Enjoy debugging!!!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s