4

I want to do PHP works on My Mac book. However, after I installed Php storm, and tell the PHP Interpreter's location, it causes error:

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

Obviously, I should install php-cgi.

I found an answer on How do I enable fastcgi on my Mavericks using PHP 5.4.24?. It says I should re-install PHP with some options, both fastcgi.

brew install php54 --with-fpm --with-debug --with-cgi --with-libmysql --with-homebrew-curl
brew install fastcgi

I am considering that: Since I have the default PHP on my Mac, must I re-install a new PHP ? Can I install *cgi as a plugin of the default php ?

Community
  • 1
  • 1
chenzhongpu
  • 6,193
  • 8
  • 41
  • 79

3 Answers3

6

To get the latest version (or whatever version you already have) on your MacBook, use:

brew install php --with-cgi --with-debug --with-libmysql

Note that Benjamin's answer is similar. However, it's not ideal to install v54 when I'm already on v717, so using just "php" without the version would get the latest one.

Pang
  • 9,564
  • 146
  • 81
  • 122
Heider Sati
  • 2,476
  • 26
  • 28
  • 3
    `Sierra (10.12.6)` returns with `Error: invalid option: --with-cgi` With `php -v PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies` – Roy Hinkley Jul 01 '19 at 19:12
  • 3
    Yes, 2 months ago brew / php in all of it's wisdom removed the "--with-" options i.e. anything with "with" will no longer work (used to before). The latest update is to install the PHP version using the @version instead. i.e. something like brew install php@7.2.19 , this will create a new folder under your /usr/local/Cellar/php/7.2.19/... and from there you could reference it on your apps. I am doing the same right now, hope that helps. – Heider Sati Jul 03 '19 at 06:05
1

As you already said, you installed PHP without --with-cgi. The problem is that CGI is an integral part of PHP and therefore needs to be added at compile time. Reinstalling PHP using brew however won't affect your settings in php.ini so there shouldn't be any reason not to reinstall it:

brew install php54 --with-cgi --with-debug --with-libmysql {more options here}

This does not overwrite the default installation of PHP on your Mac. After installation homebrew will show you how to make it start when you start your Mac.

(Sidenote: You should consider upgrading to at least 5.5. Be careful though as this deprecates the use of mysql_* in favor of mysqli_* and PDO. More details about that on http://php.net/manual/de/migration55.deprecated.php).

Benjamin Schmidt
  • 1,051
  • 13
  • 29
0

I was searching for the answer to this, but I'm not using Storm, and I want the latest version of PHP 5. I was able to get it working using the following:

First, make sure you don't have an old version of gcc laying around from before you upgraded OS X. In my case, I needed to:

brew uninstall apple-gcc42

Then get the PHP source and install it with CGI enabled:

brew tap josegonzalez/homebrew-php
brew tap homebrew/dupes
brew install --enable-cgi php56

I used this to set up a Rack-based project that runs PHP in CGI mode.

Robin Daugherty
  • 7,115
  • 4
  • 45
  • 59