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

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).


I had this same issue. I have the php installed but I need the CGI module. For Ubuntu users it is easy, just run this command:

sudo apt install -y php7.2-cgi

This command will install the stable version of php that is 7.2. You can install the version 7.1, 5.5, or what ever you need.

For Mac user you can install using this script:

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2

Check this link or read the php documentation for more information.


These are the steps to solve this common issue:

  1. Setup Brew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. Update Brew: brew update

  3. Add repo: brew tap homebrew/php

  4. Install PHP: brew install php

    • Go to PhpStorm Preferences menu follow the Languages & Frameworks and then go to PHP section
    • In this section click ... button next to CLI Interpreter setting
    • In Pop-up menu click + and then choose Other Local... , enter this address /usr/local/bin/php to the PHP executable: section in menu
    • Now, you are done! Click Apply and Save.