php-cgi not found in PhpStorm resulting in 502 bad gateway

Robert Cooper picture Robert Cooper · Dec 6, 2017 · Viewed 13.8k times · Source

I'm trying to run a simple php file with PhpStorm (v2017.3). It should output a var_dump, but I constantly encounter a 502 bad gateway error in my browser when running the script. I receive the following error in the PhpStorm:

php-cgi not found: Please ensure that configured PHP Interpreter built as CGI program (--enable-fastcgi was specified)

When I run php -v in my terminal here is the output:

PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Here are the things I've tried so far:

Answer

YvesLeBorg picture YvesLeBorg · Dec 6, 2017

Homebrew typically installs the binaries in the /usr/local/bin folder. To finalize this installation, you should tell PhpStorm which interpreter it is using. If you dont do the following step, PhpStorm will autodetect the php shipped with OSX.

Open preferences, go to Languages & Frameworks, select PHP, and you will see the appropriate settings. For the PHP Ececutable, there is a ..., click on it and you will see :

preferences

Just navigate to /usr/local/bin and click on the php binary, the one from homebrew.

ps : the 'ini' files you need to edit are in /usr/local/etc/php/M.m where M.m are major.minor version of the installed php (7.1 in your case).