23

So I recently change to ubuntu and I am trying to setup my environment again and I manage to install LAMP and phpmyadmin and phpstorm.

But what I can't mange to do is to run the php script from phpStorm when I try to run the program the page gives me a "502 Bad gateway" error and when I go back on phpStorm it tells me that php-cgi was not found.

I have tried to fix the problem but couldn't find any solid answer and I am so confused right now enter image description here

Also I have successfully added the php interpreter and the xDebug

enter image description here

Martin54
  • 1,349
  • 2
  • 13
  • 34
Steve
  • 1,213
  • 5
  • 16
  • 29
  • **1)** What are you trying to debug: your script in CLI mode or via browser (web script)? **2)** If 2nd -- do you have proper web server (Apache/nginx/etc) already installed and running? – LazyOne Jun 16 '14 at 08:44
  • I do apache installed because when i type local host it tells me that it works and yes i am trying to debug it on the browser Sorry for the late response something came up when i posted this question – Steve Jun 16 '14 at 09:27
  • Also i am geting the input in the console of phpsStorm – Steve Jun 16 '14 at 09:34
  • Please create and properly configure **Deployment entry** (`File | Settings | Deployment`) and mark it as Default for current project. Once you do -- PhpStorm will use that URL (your Apache) to serve/debug your web pages. Right now PhpStorm's own simple web server is used (used by default when no deployment is configured) which, as you can see, requires PHP to be compiled/configured in certain way (can't find better words to describe this). It works most of the time just fine .. but some people are facing such situation as you do -- and it's all about PHP itself. – LazyOne Jun 16 '14 at 09:49
  • *"Also i am geting the input in the console of phpsStorm"* -- you are not doing PHP debug -- the screenshot shows that you do JavaScript debug where JavaScript console allows you to enter and execute commands (just like Console from Dev Tools in Chrome/Firefox/etc) – LazyOne Jun 16 '14 at 09:50
  • Useful links to go trough: **1)** http://confluence.jetbrains.com/display/PhpStorm/Tutorials **2)** http://blog.jetbrains.com/phpstorm/?s=webinar+recording; **This one in particular:** http://blog.jetbrains.com/phpstorm/2013/07/webinar-recording-debugging-php-with-phpstorm/ – LazyOne Jun 16 '14 at 09:51
  • Okay now the problem i am haveing is that it is only outputing to the console and when i go to the brower is it is giveing me this Not Found The requested URL /test.php was not found on this server. And i am not type the addres myself it just redirects me to that page. – Steve Jun 16 '14 at 09:58
  • I'm sorry -- I cannot advice you with that little info as I have no clue on what you have "fixed" and how. In any case: it's all about misconfiguration on your side and not actual PhpStorm issue. If you provide enough info then maybe i will be able to help a bit more. – LazyOne Jun 16 '14 at 10:43
  • Okay, You are right i am sorry.So i did as you told me i went on file settting and deployment and added one with the type "In place" Now it runs on the console on php Storm but when i get redirected to the web browser "Google Chrome" It gives me the 404 error. I also noticed that when i type for example localhost/test.php it gives me that error aswell and the file does exsist in the /var/www – Steve Jun 16 '14 at 10:50
  • Screenshots please .. because I'm confused. But in any case: PhpStorm can have multiple type of Run/Debug Configuration (the drop down box next to Run/Debug buttons). The entry of "PHP Script" type is for executing in CLI mode. Many others (like "PHP Web App") is for executing the same script via browser. As for "404 error" -- double check the file path (full IDE screenshot with that file open should show the actual path). For example: your first screenshot shows that the file on screenshot is located in `~/Downloads/` folder – LazyOne Jun 16 '14 at 10:59
  • So first of all i did state before i am useing ubuntu as an OS Nowi Did install lmap successfully because when i type local host i tell me that it works. Now I have this project that i am trying to run from phpstorm. But it gives me the follow errors http://imgur.com/4Bm60l3 http://imgur.com/ruBmcvT Now i have the following to start debuging http://imgur.com/HrXct2b – Steve Jun 16 '14 at 11:04
  • Those errors tell that you are using **PhpStorm's own built-in simple web server** and NOT your Apache. It is used by default by IDE when no Deployment entry is configured. Unfortunately your PHP installation (for some reason) cannot be used with PhpStorm's built-in server. If you want to use Apache -- configure deployment. – LazyOne Jun 16 '14 at 11:09
  • This manual explain what Built-in web server is and how it works: http://confluence.jetbrains.com/display/PhpStorm/Using+the+Built-in+Webserver+in+PhpStorm . – LazyOne Jun 16 '14 at 11:16
  • Ill try to figure it out then. Thank you for your time. – Steve Jun 16 '14 at 11:30
  • There are some manuals for installing/configuring "LAMP" stack for Windows/Mac (but not for actual Linux) -- maybe you will find them useful: http://confluence.jetbrains.com/display/PhpStorm/Configuring+PHP+Environment – LazyOne Jun 16 '14 at 11:41
  • @Colosuslol :I have the same problems with you.I am on Ubuntu.How did you fix that?Thanks – Dion Sep 25 '14 at 13:39
  • @sokratis https://launchpad.net/~ondrej/+archive/ubuntu/php5 i just re installed the php here is ppa you can add to get the latest version.Tell me if it helps – Steve Sep 25 '14 at 14:03

8 Answers8

59

on linux ubuntu

For PHP5: sudo apt-get install php5-cgi

For PHP7: sudo apt-get install php7.0-cgi

sgiri
  • 691
  • 12
  • 28
CosmoRied
  • 876
  • 2
  • 10
  • 8
  • I encountered the same problem on **Mac OS**. How can I install **php5-cgi** ? (cannot search it on **brew**). See more [link](http://stackoverflow.com/questions/27232483/how-to-install-php-cgi-as-a-plugin-in-mac-os-os-x-10-10) – chenzhongpu Dec 01 '14 at 16:39
  • PHP7: `sudo apt-get install php7.0-cgi` – jim smith Nov 22 '16 at 10:24
5

I faced with the same problem. After replacing /usr/bin/php5-cgi with a little shell script I found that error

Host 'localhost' has multiple addresses. You must choose one explicitly! Couldn't create FastCGI listen socket on port localhost:56468

After commenting 127.0.0.1 localhost in /etc/hosts the problem seems to be solved. After commenting IPv6 hosts the problem seems to be solved:

# The following lines are desirable for IPv6 capable hosts
# ::1     localhost ip6-localhost ip6-loopback
# ff02::1 ip6-allnodes
# ff02::2 ip6-allrouters
vbarbarosh
  • 3,502
  • 4
  • 33
  • 43
3

for mac:

  1. install XAMPP (it's easy and straight forvard) it comes with apache and php interpreter

  2. in phpstorm in settings ->php -> interpreter choose path /Applications/XAMPP/bin/php

  3. phpstorm in settings -> build, ... -> Deployment add in place server, url root localhost

More info can be found on jetbrains web page

This helped me to solve this problem and run php by clicking on web browser icon inside phpstorm.

and don't forget to turn on apache in xampp --> manage servers!)

Denys
  • 114
  • 1
  • 6
  • Thanks! I had MAMP installed, and was able to use the php located at /Applications/MAMP/bin/php/php7.0.10/bin/php – Matthias Dec 04 '19 at 21:13
2

If it's not already done install Homebrew :

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

Now, that we've Homebrew, tap php repositories by entering this on your terminal :

brew tap josegonzalez/php
brew tap homebrew/dupes

Check what options are available for PHP 5.4 :

brew options php54

Now install/build PHP 5.4 with some option (in your case PHP-FPM with CGI) :

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

Note : If you're not going to use Apache add --without-apache, if you need others things, just check the options and add what you need

Now, check if PHP-FPM is enable by typing this in your terminal :

php-fpm -v

If you get this :

PHP 5.4.24 (fpm-fcgi) Copyright (c)

1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013

Zend Technologies

You just installed PHP with FCGI like a boss..

Found it Here

Community
  • 1
  • 1
Tanmay Baranwal
  • 185
  • 3
  • 17
1

Basically the who page says to do this.

  1. Download the interpreter thing oh php from php.net.

  2. Do make install

  3. Make a file called newpath.txt and add to it

    PATH=~/custom/php5/bin:$PATH export PATH

  4. Type cat newpath.txt >> .profile

I will make a youtube video and upload it.

user3756718
  • 103
  • 1
  • 9
1

I also experienced the same problem before, however to have the right PHP version installed for your current version is the first step, then before starting the IDE, ensure that you have the php7.x-cgi version installed open the terminal and input

sudo apt update && sudo apt install php7.x-cgi

replace the x with the version number, then after that you need to configure your IDE to find the path to your PHP installation directory

Aad Mathijssen
  • 630
  • 9
  • 22
Melchi
  • 11
  • 1
0

In the "PHP-CGI Server" tab in phpStorm you see the error:

/usr/bin/php-cgi -e -b localhost:52109
Host 'localhost' has multiple addresses. You must choose one explicitly!
Couldn't create FastCGI listen socket on port localhost:52109
PHP-CGI Server terminated

There curently seems not to be any fix for this known bug: https://youtrack.jetbrains.com/issue/WI-24373 Commenting out either the IPv4 or the IPv6 address for localhost in /etc/hosts (on Linux) is a workaround.

0

I also had this problem. It depends on your version of php that you want to use it as interpreter in your PhpStorm.

This error message shows that PhpStorm needs to CGI binary to execute your code.

I'm using Ubuntu 18.04 and PHP version that I have used is 7.2.

You need to install modules based on your application requirements. So you use this following command to search available PHP 7 modules in the package repository:

sudo apt-cache search php7*

Now you can see all of available modules (also for cgi) in repository. Now You must install the required PHP modules on your system as below command. Make sure to install packages for correct PHP version by specifying the version with the package name. Without defining the package version, it will install the latest package. E.g. for me, I need php7.2-cgi :

 sudo apt install php7.2-cgi

Now cgi is installed. You must restart PhpStorm and test it again. It works well for me.

Mehdi Soltani
  • 163
  • 3
  • 13