PhpStorm, OS X, Macports and the Hunt for php-cgi

18 June, 2024

I love PhpStorm, but even though I've been using it forever, much of it remains a mystery. The latest problem I had was getting it to work with xdebug in the browser (again) after upgrading to version 8.  This turned out not to be a PhpStorm issue (see content/phpstorm-and-xdebug-browser-missing-instruction), but the time and effort it took to resolve revealed again that, often, the PhpStorm help file is all but helpful. 

Before I succeeded in getting it working with xdebug in the browser, it was working with xdebug within the IDE, debugging a standalone script. Once I got it working in the browser, it would no longer debug a script within the IDE. It would jump to the browser, which would give a Bad Gateway error, and the IDE would give me a popup complaining that php-cgi could not be found.

I'm using Macports on my Mac, and here is what I needed to do in order to get xdebug working for standalone scripts.

  1. Install cgi for your version of php. I'm using php 5.5. If you're using, for example, php 5.4, change the '55' to '54'.

    sudo port install php55 +apache2+fastcgi fcgi php55-cgi


  2. Restart apache. I do the following in my environment so it doesn't mistakenly use the apache instance that came with OS X

    sudo /opt/local/apache2/bin/apachectl restart


  3. Create a symlink in /opt/local/bin. Again, change '55' to your version, if not php 5.5.

    ln -s php-cgi55


  4. Make the changes in the PhpStorm preferences

    • In the IDE, go to Preferences | PHP and click ... next to your current interpreter

    • Click + on the top left of the Interpreters window

    • Choose Other Local as the location

    • Set the name to PHP-CGI and make sure the path is correct

Login or Register to Comment!