0
votes

I have tried many ways to debug my remote server but I am unable to do so. My ftp and sftp and remote db is configures to my phpstorm 9 but I cannot debug my remote server it is connecting to my mamp server and debugging ,y local files but not connecting to server username and password . Basically it fails at mysql_connect but works for mamp.How can I make it deubug with server.Everything else is synced with server but I cannot debug. I really appreciate any help.

Edit: Should I install x-debug on my server(cpanel) also ?

php.ini

[xdebug]
zend_extension="/usr/local/opt/php55-xdebug/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
1
It's almost impossible to help you given that you did not provide any information about your setup. Please read this article first. You can ignore the "Starting the debugger" sections as you probably want to debug web pages and not CLI scripts. In this case you start the debug session using the IDE. Having the XDebug PHP extension installed and loaded is mandatory, of course. - axiac
@axiac I have updated the Q . I have all the above parameters in php.ini file. But its still not working . Also I have ssh user@remote-host -R 9000:localhost:9000 - jason
Am I missing something .I am on it from last 2 days.Please let me know. - jason
Also I did not get “PHP_IDE_CONFIG" .How should I do it ? - jason
XDebug is a PHP extension. It must be installed and loaded by the PHP on the same server where PHP runs. If you want to debug the code running on the remote server then you need PHP installed on the remote server and also the XDebug extension installed and properly configured on the remote server too. It is the link between the PHP interpreter (which runs the code) and the debug client (PhpStorm in this case). - axiac

1 Answers

0
votes

Maybe I didn't understand your question/problem. These are the ways you can debug your code

Debug the local code that uses the local database

This is the easiest setup and it probably already works on your system. You have all the files on the local computer and also you have an instance of MySQL running on it. The code connects to localhost:3306, the xdebug extension is installed and it can connect to PhpStorm, everybody is happy.

Debug the local code that uses the remote database

You can have all the PHP files on localhost and use the local mamp stack to debug it; you control the environment, xdebug works and happily collaborates with PhpStorm. You want the code to be able to use the remote (live) database.

In this case you need a way to access the database. Either you create a MySQL user that allows you to connect from the IP address of the local computer (a firewall along the way might prevent this), or start a ssh session that creates a tunnel from the local port 3306 (or any other open port you choose) to port 3306 of the database server (assuming the host where you ssh is allowed to connect to it). You can do this by running

ssh user@remote_host -L 3306:database_host:3306

(replace user, remote_host and database_host with your actual values)

If you have a MySQL server installed and running on localhost then the local port 3306 is not open and ssh cannot use it as the source port of the tunnel. Use another port instead (let's say you use 13306):

ssh user@remote_host -L 13306:database_host:3306

Modify the local configuration files of your application to use localhost as database server and 13306 as database port.

Debug the remote code

If you want to debug the live code (it uses the live database) then you have to upload the code on the web server (the live environment) and make it work there (be able to connect to the database etc).

In order to be able to debug it you need to have the xdebug PHP extension installed on the server and properly configured in the server's php.ini configuration file.

The debugger (the remote xdebug extension) needs to connect to your local computer where PhpStorm is listening on port 9000. This is either impossible or making it happen requires changing configuration here and there in several places (that might be out of your control); we better forget about it.

We can use the ssh tunnel trick: start a ssh connection to the server that creates a tunnel from local port 9000 to the servers port 9000:

ssh user@remote_host -L 9000:localhost:9000

Test if it works

PhpStorm provides a tool that uploads a script on the web server then tries to access it to check if the xdebug extension is properly configured. Depending on the version of PhpStorm you use, you can find it either in the menu (Run -> Web Server Debug Validation, on PhpStorm 9) or somewhere in the Settings (PHP -> Servers or around, on older versions).