Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • Reinstalling PHP with homebrew with brew uninstall php71 and then brew install71.
  • Adding the --with-cgi option to my brew install php71 command
  • Read through the following threads: phpStorm problems with php-cgi, php cgi error in PhpStorm when php-cgi is installed
like image 479
Robert Cooper Avatar asked Dec 06 '17 18:12

Robert Cooper


4 Answers

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.

like image 79
Teocci Avatar answered Nov 16 '22 12:11

Teocci


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

like image 18
YvesLeBorg Avatar answered Nov 16 '22 12:11

YvesLeBorg


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.
like image 6
Peaceman Avatar answered Nov 16 '22 13:11

Peaceman


I got the same error using PHPStorm with MAMP, so in this case I configure the PHPStorm to using php-cgi installed by MAMP. For this in PHPStorm, open Preferences —> Languages —> PHP and configure like that:

enter image description here

like image 1
3 revs, 2 users 80% Avatar answered Nov 16 '22 13:11

3 revs, 2 users 80%