PHPStorm by JetBrains is considered by many to be one of the best integrated development environments (IDEs) available for PHP. PHP is a server-side scripting language primarily designed for web development, but it is also used as a general-purpose programming language. It's estimated that as of January 2013, PHP was installed on more than 240 million websites and 2.1 million web servers. The very popular WordPress platform is built upon PHP. Originally, the acronym PHP stood for Personal Home Page, but it has since been redefined and now stands for PHP: Hypertext Preprocessor, a recursive backronym.
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.
Xdebug Configuration
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:
After making these changes, restart Apache. In Ubuntu, the command is “service apache2 restart."
PHPStorm Configuration
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:
Google Chrome
I've found that PHPStorm works best with Chrome when debugging. Chrome needs the Xdebug helper extension to connect to Xdebug for PHP and the JetBrains IDE Support extension to connect to PHPStorm for HTML and JavaScript. Both of those are pretty straight forward to setup. The only configuration needed is to set the session ID for Xdebug Helper to PHPStorm.
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.
Port Forwarding
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.
Leave a Reply