phpStorm problems with php-cgi - php

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
Also I have successfully added the php interpreter and the xDebug

on linux ubuntu
For PHP5: sudo apt-get install php5-cgi
For PHP7: sudo apt-get install php7.0-cgi

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

for mac:
install XAMPP (it's easy and straight forvard) it comes with apache and php interpreter
in phpstorm in settings ->php -> interpreter choose path /Applications/XAMPP/bin/php
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!)

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

Basically the who page says to do this.
Download the interpreter thing oh php from php.net.
Do make install
Make a file called newpath.txt and add to it
PATH=~/custom/php5/bin:$PATH
export PATH
Type cat newpath.txt >> .profile
I will make a youtube video and upload it.

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

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.

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.

Related

Disable blackfire module temporary

I've sucessfully installed the blackfire agent, cli tool and probe and it works fine. I've disabled the xdebug module while profiling with bf.
Now I want to use xdebug as I did before, but xdebug does not work, it just won't enter a debugging session. No breakpoint and not even xdebug_break work. A quote from the producers website says:
Known incompatibilities
Please note that PHP compiled with debug are not supported and that
the Probe may conflict with XDebug or XHProf; disable those extensions
when enabling the Probe.
Is there a way to disable the blackfire agent WITHOUT uninstalling the whole blackfire tool chain ? Moving the file /etc/php5/conf.d/90-blackfire.ini to a backup location didn't work.
Update
What works is uninstalling the php agent sudo apt-get remove blackfire-php. But I'm pretty sure there must be a better solution.
You can simply edit the file /etc/php5/conf.d/90-blackfire.ini and comment the following line extension=blackfire.so. Don't forget to restart apache2 or php-fpm
You can run the next command to turn off PHP extensions/modules:
$ sudo phpdismod blackfire
The opposite of this command is:
$ sudo phpenmod blackfire
To apply all changes you must restart your service. Example:
$ sudo service php7.4-fpm restart

Is it possible to use Xdebug with the built in PHP test server?

Basically my question says it all.
I'd like to be able to inspect the state of the variables of my script, set breakpoints etcétera, without the need to install Nginx, apache or PHP-FPM?
Is this doable, if not what would be my options?
Ok so parting from this article I've managed to use xdebug.
I installed PHP 5.5 on Mac OS X 10.10 using homebrew
Install PHP if it has not been installed, make sure to install it with the xdebug extension;
in my case I used$ brew install php55-xdebug or if you have pecl and php already installed use $ pecl install xdebug.
You can check if the extension is installed by executing $ php -m | grep xdebug.
If you use VIM as your "IDE", I'd recommend to install the vim pathogen plugin, then install the xdebugger vim plugin; which I've modified to be pathogen compatible.
$ cd ~/.vim/bundle && git clone https://github.com/Triztian/xdebugger.git
Next we have to enable the xdebugger extension; to do so first you need to find out which php.ini file is being loaded, you can check that by running $ php -i | grep "File => /". After you've found the correct init file you must add the follwing lines at the end:
xdebug.remote_enable=On
xdebug.remote_autostart=On
If using PHP's built-in development server, you can use the -c argument to specify a php.ini file.
Now, start the php development server (in my case $ php -S localhost:8080 -c /usr/local/etc/php/5.5/php.ini) and open VIM. After VIM is open press <f5> so that the xdebugger starts listening for a connection; on your browser navigate to localhost:8080/index.php (or any php script) so that it triggers the xdebugger connection if everything has been setup correctly.
You should no be in a debugging session, look at the plugin's readme to see how it works.
You can use php built in web server. It was mean't to be used for development.

PHP not running after upgrade

I'm having some trouble getting PHP to run under Apache after updating my software. On my Amazon AWS running AMI, I followed this guide here, with the specific commands:
sudo yum remove httpd* php*
sudo yum install httpd24 php55
After updating the apache config files to use the newer directives, I can get to the server, but the PHP is just echoing out on the screen.
I checked to make sure that there is a php.ini file being read, that the module is loaded in Apache, the server is running, and I can execute php from the command line.
Anyone have any ideas on what I should check next?

Enable XSL on Ubuntu 12.04

I am trying to enable XSL on Ubuntu 12.04 but its failing. I did this locally on my Ubuntu 13.04 and it was successful. Basically the following worked on my local computer.
apt-get install php5_xsl
edit php.ini file and add extension=php5_xsl.so
restart apache
I repeated the same procedures on my production server running Ubuntu 12.04 and PHP version 5.5.12 but the extension is not getting loaded from the phpinfo. I have also changed the extension=php5_xsl.so to extension=xsl.so because this is what in the extension directory.
I read that I might need to recompile PHP but I am not sure of this steps.
Try this:
sudo apt-get install php5-xsl
sudo php5enmod xsl
sudo service apache2 restart
Why:
http://www.lornajane.net/posts/2012/managing-php-5-4-extensions-on-ubuntu
What's happened here is that all debian-flavoured unixes have adopted
this standard for their PHP 5.4 packages, so if you're using debian,
ubuntu, or any of their relatives with PHP 5.4, you'll see a directory
structure like this. When you add a module to PHP, you'll add a file
to the mods-available directory enabling the module and adding any
config specific to it. If you want to enable the module, just do:
php5enmod http
This simply creates a symlink from the usual conf.d directory to point
to where the real files are in mods-available, prefixed with a number
that indicates the priority of the module. By default, the priority is
20.
Using this approach means we can toggle things on and off without
commenting out big chunks of config files and leaving them lying
around - if this seems familiar then that's no surprise; debian-like
linuxes manage their apache configuration in just the same way. Any
packages that you install using aptitude will use these exact same
commands to set up the configuration and then symlink it correctly. To
unlink, use the delightfully predictably-named php5dismod :)

PHP extensions not loading in phpinfo

So I'm running MAMP on Mountain Lion and I've installed gmagick and imagick using pecl, both are relase candidates (mainly because gmagick doesn't have a stable release and imagick 3.0.0 doesn't install, it gives a make error). The modules appear when I run php -i in the terminal but not in phpinfo(), I have checked the php.ini it is the same for both so that is not the issue.However I have installed bitset(which is a stable release) and it appears in phpinfo() and php -i. So my question is does PHP have any configuration option that does not load extensions if they are not stable? Btw, I did restart my server after the changes to the ini file.
You will probably now have two php installations on your machine. Mountain Lion ships with a preinstalled php version. Trylocate php.ini in Terminal to find out how many php.inis are installed.
In your phpinfo() page there is also noted which php.ini is in use. You might want to open the exact php.ini which is used for your phpinfo() and make sure the extentions are loaded.
There should be two lines like
extension=/path/to/gemagicext/gmagic.so
extension=/path/to/imagick/imagick.so
I faced a similar problem with php-fpm and nginx server. The problem was due to the fact that the updated php configuration was not reflected in the current active php-fpm worker processes. I have to manually kill the fpm process and restart it again to have the updated extensions info.
Steps that worked for me:
1) Look for active php-fpm process
ps ax | grep "fpm"
mostly this will list more than one process
2) kill process manually
kill -9 [pid_got_from_previous_command]
3) restart php-fpm process
sudo service php5-fpm start
Note: Trying something like sudo service php-fpm reload or sudo service php-fpm restart didn't work since the old child processes retained the old configuration. Killing the active processes and restarting php fpm what updated the phpinfo for me.
I had the same problem CentOS 6.6 x64, php 5.5.27 and I followed the steps from
http://php.net/manual/en/imagick.installation.php
First of all download a tar image of the ImageMagick install from here:
sourceforge.net/projects/imagemagick/files/
Unpack it and then from terminal issue the following commands:
1. "cd ImageMagick-6.9.1-10" - go where you placed the folder
2. ./configure
3. make
4. make install
5. make check
6. install imagick extension from pecl.php.net/package/imagick/download 3.1.2
7. cd imagick-3.1.2
8. phpize
9. ./configure --with-imagick=/opt/local
10. make
11. make install
12. Copy imagick.so in your PHP extensions folder and add extension=imagick.so in php.ini
Restart apache: service httpd restart
I am sure this problem is related to your extension and PHP server compatibility. I encountered such problems when I created my own extensions. Your extension should compatible with your PHP server in three main attributes:
1- The Zend API number which your PHP server is configured with ( in phpinfo() you can find this number), this number should be the same with your extension header file at build time.
2- The compiler version on your PHP server and your extension must be the same.
3- Thread safety in your PHP server is important. If you use thread-safe server then your extension must be built with php thread-safe library and if you use non-thread safe server you should build your extension with PHP-nts library.

Categories