While PHPStorm is an excellent product and highly recommended, it's documentation falls short. As an author of quite a few books, I may be overly critical of technical documentation. I like simple to understand directions.
Recently, I've been working on a few projects for Blue Olive Strategic Solutions out of Florence, Alabama. Blue Olive is an award–winning advertising agency made up of talented industry professionals with diversified backgrounds and significant expertise in social marketing, logo design, graphic design and website design and development. One of these projects is a home-grown PHP application the agency depends upon for scheduling, task management, and billing. It was written over 7 years ago for a very early version of PHP and has not been maintained since the original developer parted the company. I was asked to bring the application up to current standards and migrate it to a new server. After several weeks and over 1,000 changes, I had the application working well on my MacBook Pro, which I use for development. Of course, when I moved all of the source code to the new server, it doesn't work and I found that I had to setup my PHPStorm to work with XDEBUG on the remote server. It took me a day and much trial and error before I got everything working, so I thought I'd share what I learned.
There is a lot of information on the web about getting PHPStorm to work with XDEBUG in your local environment, but when it comes to a remote server, the documentation and available tutorials are lacking. In fact, many of the tutorials I looked at call “localhost" a remote server, which it is not. The remote server I'm working with is a Virtual Private Server (VPS) setup in the Amazon cloud. It is running Ubuntu 14.04 LTS. If you're running a different Linux distribution, these instructions may or may not work for you. All I can say, is try. You have nothing to lose.
The first thing we're going to do is setup the Xdebug configuration. The Xdebug configuration is either inside php.ini or in another ini file often called xdebug.ini. On the Ubuntu server, the xdebug.ini file is found in the /etc/php5/mods-available directory. There is also a symbolic link to this file in the /etc/php5/apache2/conf.d directory. The contents of the xdebug.ini file are:
xdebug.remote_connect_back = 1
xdebug.var_display_max_data = 2048
xdebug.var_display_max_depth = 128
After making these changes, restart Apache. In Ubuntu, the command is “service apache2 restart."
The most important thing to do with PHPStorm is to make sure the Debug port is set to the same port you designated in your Xdegug.ini file. To set the PHPStorm Xdebug port, go to the preferences file and select PHP/Debug, then follow the example as in the image below:
Note: PHPStorm can only connect to one port for Xdebug. This means that every time we change a site from the default port, the IDE needs to be reconfigured.
In order for the Xdebug connection to reach your development box, you need to make certain the Xdebug port is forwarded from your router to your development machine. Each router is different and you should consult your router's documentation to determine exactly how to forward ports. As a representative example, my router is an ASUS RT-AC66R. The following screen print demonstrates how port forwarding works in my setup.
Note: Port forwarding only works if you assign a static IP address to your development machine.