IDE loads index.php once then 502 Bad Gateway

First time user with fresh install running PhpStorm 2016.3.2 x64 on Windows 10 Pro with Oracle's Java SE SDK runtime. I'm attempting to use IIS Express as the application server with Xdebug.

IDE Project is Default PHP with an index.php file that calls phpinfo(). The 1st time the IDE loads index.php phpinfo() is processed and I can see a Xdebug section.

But every time I attempt to reload index.php a 502 Bad Gateway error is returned.

Here's what I know...

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Xdebug                        ;
;https://xdebug.org/wizard.php ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
zend_extension = "C:\Program Files (x86)\iis express\PHP\v7.0\ext\php_xdebug-2.5.0-7.0-vc14-nts.dll"

; Loads URL 1st time
http://localhost:63342/ps-01/index.php?_ijt=asosa3f1qlhacapq2p1d7qmg06

; Subsequent index.php load requests from IDE
; or copy and pasting URL into new tab or into another browser returns
502 Bad Gateway PhpStorm 2016.3.2

; Settings > Languages & Frameworks > PHP
PHP language: 7
CLI Interpreter: PHP 7 (7.0.9)

; Settings > Languages & Frameworks > PHP > Debug > Servers

Name: localhost [*] Shared
Host: http://127.0.0.1 Port: 63342 Debugger: Xdebug

; Build, Execution, Deployment
Haven't touched any settings

Here's what I don't know...
What to do to configure the IDE correctly and move on to learning other configurations for WordPress and HTML/JavaScript project types

Comments?

14 comments
Comment actions Permalink

I've been working on this all day following documentation to set up PHP and I have determined the same SNAFU occurs whether I configure for PHP 5.5 or PHP 7. I can see Xdebug show up when phpinfo() loads but again if I close the browser and run index.php again 502 Bad Gateway occurs.

Perhaps this is an IIS Express problem? Perhaps conflicts with ports but then why would phpinfo() load the first time but not subsequent load requests?

0
Comment actions Permalink

Hi there,

You are using PhpStorm's own simple built-in web server (based on the URLs you have provided) .. which does have such issues

https://youtrack.jetbrains.com/issue/WEB-17317

Solution -- use standalone web server like Apache/nginx/IIS or alike

(P.S. On Windows you can use full IIS -- you just need to install it from Windows components; If you prefer Apache -- you can use vanilla one (original) or install it as part of some bundle -- WAMP/XAMPP/ectc (there are quite a few bundles around))

0
Comment actions Permalink

Thank youi for showing up Andriy I really want to learn to use PhpStorm as I am moving away from C# and VisualStudio to learn PHP and WordPress --but-- JetBrains wants me to buy a product that is apparently not documented for use on Windows and according to the link you referred to the company is not interested in patching its bugs.

Before reading further if there is documentation to configure PhpStorm with IIS please refer as there is none I have been able to find and none for IIS Express else...

I don't like the *AMP for Windows because they all hijack default ports. So that breaks my use of other development tooling notably from Microsoft. That said, I already have MySQL installed and running fine on Windows 10. I have experience with IIS and IIS Express.

My current CLI Interpreter configuration points to PHP in the root of IIS Express. Its been the only way I could also see Xdebug get recognized by phpinfo() which is only loaded when configuring with PHP 7 and not PHP 5.5 both of which I've tried using as my PhpStorm CLI Interpreter but again the 502 SNAFU persists.

I see the port ub the address of the URL that PhpStorm server apparently uses. I though of working around that by the following

; Settings > Languages & Frameworks > PHP > Debug > Servers

Name: localhost [*] Shared
Host: http://127.0.0.1 Port: 80 Debugger: Xdebug

That did not work either but I did observe the PGP-CGI Server report
"C:\Program Files (x86)\IIS Express\PHP\v5.5\php-cgi.exe" -e -b 127.0.0.1:50426

See the port assignment?
Some process I do not understand continues to force port assignments which may be the conflict.

php-cli -e generates extended information for debugger/profiler

php-cli -b <address:port>|<port> Bind Path for external FASTCGI Server mode

So I remain clueless else if absolutely forced I will install XAMPP and see how far I can get. I just saw an image of the XAMPP setup implying I can configure port assingments but last time I tried *AMP installs I had to go do everything manually which led to forgetting and such.

0
Comment actions Permalink

Windows 10 will now run Linux bash natively and allow you to run a true Apache server. https://msdn.microsoft.com/en-us/commandline/wsl/about 

1
Comment actions Permalink

Worth perusing considering the components are from the Ubuntu OS and in Beta. I have no *nux bias as I came up on Unix back in the day but the real point to be made is my growing awareness that JetBrains sells software to be run on Windows which appears they do not even document and worse as a reference from Andriy is buggy and is not patched and I am having a serious flare up of the imposter syndrome.

https://youtrack.jetbrains.com/issue/WEB-17317


Is there not a known method to force PhpStorm to stop using its built-in web server? With my meager experience with this IDE it seems to me that is what is causing the conflict.

I only have a couple of weeks eval left to determine if I should pay for this software that happens to be considered the best of the best for developing WordPress apps.

0
Comment actions Permalink

@Clinton

>Before reading further if there is documentation to configure PhpStorm with IIS please refer as there is none I have been able to find and none for IIS Express else...

There is no special config from IDE side for any particular web server -- be it Apache or IIS. If anything it will be the same for any web server you will use.

It just happens that you would usually run final code on Linux platform (where PHP works better than on Windows) so it assumes that Apache/nginx is most likely will be your web server .. so you would try to use Apache for local dev as well.

(as alternative to using local web server consider VM -- be it vanilla VM (VMware Workstation/Oracle VirtualBox) or Vagrant-managed VM (lots of pre-built images) .. or maybe even Docker container...)

 

>I have experience with IIS and IIS Express. 

That's good -- then you should have no big issues with configuring PHP to run under IIS.

I've pretty much never used IIS Express (only for fixing/making changes in one existing ASP.NET app .. and that was like back in 2007 or so (Visual Studio 2005)).

But I do use IIS as web server on my Windows 7 (and now Windows 10) .. plus most of my sites run under IIS on Windows Server 2008 R2/2012 R2 and now 2016. They all use the same config approach (for PHP part) -- the manual/general instructions can be found on https://php.iis.net/ site (that's where I've learned it)

In short:

  • You must use NTS builds of PHP if you running them on IIS
  • PHP is run via FastCGI (so you need to have CGI feature to be installed)
  • You will need to change few options in php.ini for running under IIS & FastCGI. From my php.ini (the most important I believe)
  • cgi.force_redirect = 0
  • cgi.fix_pathinfo = 1
  • fastcgi.impersonate = 1 (so PHP is run under AppPool acc)
  • fastcgi.logging = 0
  • PHP handler is setup in Module Mapping feature of IIS (Handler = FastCGIModule)
  • When you will be debugging PHP script running under IIS .. you will notice that debug sessions get suddenly terminated -- that's FastCGI settings -- you need to increase time outs (to something like these):

>Name: localhost [*] Shared
>Host: http://127.0.0.1 Port: 80 Debugger: Xdebug

Host field should be just a domain name (no protocol) .. so in your case it should really be just 127.0.0.1

Port field must be the number that you see when you browse that page (if you do not see none then its obviously 80 for plain http). AFAIK IIS Express likes to launch new servers on different ports .. so I'm not sure what to suggest here.

But for IIS it's all much easier -- fake domain name via hosts file and standard HTTP port 80 (hot to setup a site in IIS you should know)

>Is there not a known method to force PhpStorm to stop using its built-in web server?

What for? It does not cause any issues here.

In any case: you are using built-in web server because you have clicked "Preview in Browser" or similar action .. which uses built-in web server if you have NOT specified your own address/server. If you do -- IDE will use that address instead (will not affect already created Run/Debug Configurations -- you will either edit them or delete and re-create again)

Now -- the URL is takes from Default Deployment entry. If you do not have any -- built-in web server is used.

To define one -- "Settings | Build, Execution, Deployment | Deployment" and create an entry of most suitable type (e.g. "In Place" -- no file copying will occur); configure it (specify URL and paths -- make sure you have no warnings on all tabs there).

Now -- all the above is only needed if you with to use "Open in Browser" and alike actions in IDE. If you have happy to use browser directly (by either typing URL in or using bookmark) .. then you do not need this section at all.

 

>With my meager experience with this IDE it seems to me that is what is causing the conflict.

I really doubt that built-in web server is causing any of that. As a new person to this IDE and PHP you most likely misconfigured something and do not know yet how it all works.

If anything -- close IDE; go to project folder and delete .idea subfolder (this project folder); launch IDE and using "Open" point to the project root folder -- IDE will create new project from those files. This way you can start fresh without the need to use multiple projects etc.

 

----

In case if you have not seen:

(generally speaking) My suggested plan is (assuming IIS path here):

  • No PhpStorm involved here yet for debugging or stuff like that.
  • Install and configure IIS (if not done yet). Make sure that you can serve static files from such local domain (domain name can be faked via hosts file or local DNS server if you have one)
  • If all good: Install PHP and ensure that you can execute basic script on the same domain
  • If all good: Add additional extensions if needed (wincache/sqlserver/mysql/etc)
  • If all good: Create PHP Interpreter in PhpStorm and try to execute CLI scripts
  • If all good: Install xdebug (must be for the same version and the same build type (TS/NTS)) and configure it (xdebug requires at very least 2 lines in php.ini)
  • Try to debug scripts in CLI mode (easier to configure xdebug/pass debug parameters)
  • If all good: time to do web based debug

 

P.S.

>I only have a couple of weeks eval left to determine if I should pay for this software that happens to be considered the best of the best for developing WordPress apps.

Right now you can also use EAP build of 2017.1 (next major version -- see announcements in blog) -- it's still work in progress (so may have issues that stable version does not have) ... but such EAP builds have own 30-day license (every build has own 30 days)  .. so it can last longer than initial trial of 2016.3.x (stable version)

 

P.P.S.

I may assist with initial setup/config of PHP under IIS/PhpStorm & xdebug via TeamViewer if you will be really struggling (I guess 30-60 mins if all goes very well) .. I'm just not sure about actual free time (I'm in UK time zone)

1
Comment actions Permalink

Andriy you da' man. What a help you are proving to be. I will study and apply all of your comments and the resources tonight and into tomorrow. One thing that hit me while reading: I have used the Windows hosts file as a localhost redirector for many years and never thought about an entry for setup of a PhpStorm project.

I'm increasingly aware that this whole matter is my lack of experience with PhpStorm config because I even struck out with Apache installed w/ XAMPP. I'm also going to give DesktopServer a shot but first I will work your plan.

0
Comment actions Permalink

BTW -- you may also try PHP Manager for IIS -- I do not think it's a super tool (as I do have it all working without it) but for new person it may help a bit (I've used it only to see what it will tell me about my existing installation; but was useful when I wanted to learn how to install multiple PHP versions (to see how it does it) and to see how to change PHP version for specific website)

Actual project: https://phpmanager.codeplex.com/ (works for Windows 7 max -- it fails to do some proper checks on Windows 8+ (where IIS has higher/newer version)) Some workarounds: http://stackoverflow.com/questions/36985999/php-manager-iis-fails-to-install-windows-10

I've used something like that: https://github.com/RonaldCarter/PHPManager/tree/master/bin/Release (not this particular one .. as mine is an .exe file -- don't remember the URL where I got it from but this one should work as well -- or just compile your own from the sources)

http://phpmanager.codeplex.com/wikipage?title=Managing%20PHP%20installations%20with%20PHP%20Manager%20user%20interface

https://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis

 

0
Comment actions Permalink

Hello Andriy,

So far no joy on Windows 10. I've followed your comments and something is still mess up. PhpStorm will load the default website (inetpub/wwwroot) via localhost but not the new PHP project ps-01 with a call to phpinfo().

I used the hosts file to bind 127.0.0.1 to ps-01 and I used IIS Manager to create the new website but again, no joy for now. The ps-01 project won't even fire up phpinfo() and 502 Bad Gateway persists

Have you observed on your Windows 10 machine that it runs IIS 10 and apparently sets up Handler Mappings for PHP_via-FastCGI on its own?


That's it for now back to work on the SNAFU but to say I looked at the PHPManager and such and for now decided not to touch them as they are all old tooling. I'll be updating the status of this adventure...

0
Comment actions Permalink

>So far no joy on Windows 10. I've followed your comments and something is still mess up. PhpStorm will load the default website (inetpub/wwwroot) via localhost but not the new PHP project ps-01 with a call to phpinfo().

No solid ideas as of yet.

So far it could be a basic misconfiguration from IIS side of things (be it site/file access permissions/etc) ... or PHP config itself (not ready for IIS)

 

>I used the hosts file to bind 127.0.0.1 to ps-01 and I used IIS Manager to create the new website but again, no joy for now. The ps-01 project won't even fire up phpinfo() and 502 Bad Gateway persists

Are you able to serve static files from that site?

Ignore PhpStorm for now completely. Just use IIS Manager & Browser & Notepad/Notepad++ for now to ensure that you can actually run website at all (otherwise you may be getting confused with PhpStorm parts and doing unrelated checks/configs).

As per my "plan" -- your task for now is to have website working at all .. and only then, with working basic website you may go further.

 

>Have you observed on your Windows 10 machine that it runs IIS 10 and apparently sets up Handler Mappings for PHP_via-FastCGI on its own?

Nope. I add PHP manually only once (or new version when needed) and then it just runs.

It could be some tool/software that you were trying (e.g. installing PHP using Web Platform Installer feature etc)

 

P.S.

What time zone you are in?

We could try TeamViewer in my evening hours (as long as internet will be OK on my side)

 

P.P.S.

Here is the part of the initial setup script that I'm using when setting up VPS that runs Windows Server (I left only PHP related stuff; hopefully it did not break anything). I do not do anything of it on my Desktop as it already has folders setup and relaxed access permissions .. but when you have a server with only one disk C:\ and fact that one site should read only own files you need such stuff (plus, this one does not cover actual websites -- only general PHP access).

The most interesting for you part might be at very end where FastCGI and actual Module entries are created (once again -- on my Desktop I'm doing it all manually).

@echo off
@endlocal & setlocal EnableDelayedExpansion

@rem Set details here
SET RootDisk=C:
SET IISAppCmd=%SystemRoot%\System32\inetsrv\appcmd.exe
SET FixNewFoldersPermissions=yes
SET PHPVersionFolder=\php70

@rem Printing details (so we know what details were used in case of error/misbehaviour)
@echo Root Disk                   : %RootDisk%
@echo Path to IIS AppCmd.exe      : %IISAppCmd%
@echo Fix New Folders Permissions : %FixNewFoldersPermissions%
@echo PHP Version Folder          : %PHPVersionFolder%
@echo ---------------------------------------------
@echo.

@rem Small pause to allow spotting bad move/details
@echo PLEASE CONFIRM THAT ALL DETAILS ARE CORRECT
@pause
@echo.

@rem Starting here
:stepStart


@rem Create folder structure
:stepCreateFolders
@echo.
@echo -- CREATING FOLDER STRUCTURE ON DISK %RootDisk% ...
%RootDisk%
cd \

@echo **** Creating "php" folder...
@rem So righ now PHP v7.0.xx will be in C:\php\php70
md php
md php%PHPVersionFolder%
md php%PHPVersionFolder%\_logs
md php\temp
md php\temp\sessions
md php\temp\tmp
md php\temp\uploads


@rem Fix newly created folder permissions
@rem   1. Break inheritance
@rem   2. Get rid of "Creator Owner"
:stepFixFoldersPermissions
@if not (%FixNewFoldersPermissions%)==(yes) goto stepFixFoldersAddMyself
@echo **** Fixing permissions for newly created folders...
icacls.exe "%RootDisk%\php" /inheritance:d /Q
icacls.exe "%RootDisk%\php" /remove "CREATOR OWNER" /Q


@rem Assign file permissions / access rights
:stepAssignFilePermissions
@echo.
@echo -- SETTING APPROPRIATE FILE PERMISSIONS ...
@echo **** php ...
icacls.exe "%RootDisk%\php" /grant IIS_IUSRS:(OI)(CI)(RX) /Q
icacls.exe "%RootDisk%\php%PHPVersionFolder%\_logs" /grant IIS_IUSRS:(OI)(CI)(M) /inheritance:e /Q
icacls.exe "%RootDisk%\php\temp" /grant IIS_IUSRS:(OI)(CI)(M) /Q


@rem Configure IIS (defaults, common settings)
:stepConfigureIIS
@echo.
@echo -- CONFIGURING PHP SUPPORT ...
%IISAppCmd% set config /section:system.webServer/fastCgi /+"[fullPath='%RootDisk%\php%PHPVersionFolder%\php-cgi.exe']"
%IISAppCmd% set config /section:system.webServer/fastCgi /"[fullPath='%RootDisk%\php%PHPVersionFolder%\php-cgi.exe'].instanceMaxRequests:5000"
%IISAppCmd% set config /section:system.webServer/fastCgi /+"[fullPath='%RootDisk%\php%PHPVersionFolder%\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='5000']"
%IISAppCmd% set config /section:system.webServer/fastCgi /+"[fullPath='%RootDisk%\php%PHPVersionFolder%\php-cgi.exe'].environmentVariables.[name='PHPRC',value='%RootDisk%\php%PHPVersionFolder%']"
%IISAppCmd% set config /section:system.webServer/handlers /+"[name='PHP via FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='%RootDisk%\php%PHPVersionFolder%\php-cgi.exe',resourceType='File']"


@echo.
@echo == ALL DONE ==

:exit
SET RootDisk=
SET IISAppCmd=
SET FixNewFoldersPermissions=
SET PHPVersionFolder=

@pause
0
Comment actions Permalink

Andriy

I have broken the configuration down to fundamentals as you suggested; I actually did so yesterday and did the same thing using the hosts file manually on a Win8.1 machine. The hosts file method works fine on that machine as it has for years. On Win10 I'm still getting 401 and such. No joy. Got to spend much of today elswhere but wanted you to know I am sticking on this like glue....

0
Comment actions Permalink

This sounds like your AppPool settings ... or Authorisation settings for that site (so it's a IIS misconfiguration, most likely).

At Desktop I'm using only DefaultAppPool that comes with IIS by default. Then I'm configuring defaults (get applied to all new sites) for Authorisation to enable Anonymous authentication and having it set to IUSR (I guess it's all by default anyway). Works fine.

If you are using different user for your AppPool or different app pool per site (e.g. you have created new pool for new site) then it may have different settings set (different user?).

That's regarding the static files. PHP itself (php.ini) may have separate option as well (see my php settings few posts back)

0
Comment actions Permalink

Andriy I have returned!

I am running PHP in PhpStorm successfully. My next step is learning to use the debugger. Then I learn to use PhpStorm for WordPress which is why I am buying into PhpStorm due to all the rave reviews and respect WordPress developers have for this IDE. So when I got back to work tonight...

I used IIS Manager to create a Virtual Directory under the Default Directory and located the folder for the Virtual Directory in the root of wwwroot as inetpub\wwwroot\php-test for example. I fire it up and it runs as localhost/php-test and loads index.php file as expected. I then put other php files into the php-test folder and request them and they load.

When I load index.php that calls phpinfo() it shows IIS Express is the web server running the instance of PHP 7.0 which is what Visuall Studio defaults to these days. Your suposition that IIS Express uses arbitrarily assigned ports is correct as I've observed but I think that's more a function of the IDE like Visual Studio or Web Matrix that sets up the port assignments.

I can this because using this Virtual Directory method with the folder it is bound to exists in the root of the Default Website. Calling phpinfo() from the website running in the Virtual Directory not only shows IIS Express as the web server but $_SERVER['SERVER_PORT'] is port 80. Groovy stuff.

Next step I launched PhpStorm and created a new project from existing files. I figured out how to answer the configuration and poof! I'm back in business using this method.

Still no joy though using the hosts file and host headers which is stupfying because I've been using it on all of my Windows machines for several years and was the only method I ever used.  That let me put the website folders anywhere on the file system.

I tried both DefaultAppPool and the pool assigned to the same name being bound to the host header and neither worked out. 

When using IIS Manager to Create New Website and using Test Settings I've always noticed that Authorization could not be verified but before Windows 10 all of my websites would load when requested in a browser. I also always put an entry into the hosts file to bind 12.0.0.1 to some website host name. That's all there was to it until Windows 10 came along.


I even clicked that "More information about configuration and diagnosing UNC connections" link and changed Security properties on the folders and then the files adding IIS_USER to read as the documents explain but no joy. Something is really FUBAR on this box because my old tried and true host headers method on new websites created with IIS Manager mapped to their aribtrary locations on the file system just doesn't work for any type of project; html, php or asp.net.

Tomorrow I am going to try using the hosts file method-- one more time --but I am going to bind to the IP of this machine and try avoiding passing through 127.0.0.1.

If you have any remaining comments I'm still all eyes and ears as I've perused your profile and you are one mean monster of knowledge. I'm very grateful for your assitance through this trial and error period and I hope our foray into the darkest depths of Mordor remain here for other to learn from.

I've decided to purchase PhpStorm and its all your fault. :-)

 

 

0
Comment actions Permalink

The green and yellow on screenshot looks OK -- I have the same on my home dev machine .. and site/PHP code works just fine (can create/delete any files etc) -- possibly because of relaxed file access permissions etc. But on production server it's all much tighter (proper isolation -- only access files in current website folder)

 

IIS Express vs IIS -- maybe try disabling IIS Express at all? In the past it has to be started up manually....

 

For me the best way to help is to look at your situation there with my own eyes -- I may see something (that is wrong) that you might be missing (as it may look normal to you).

0

Please sign in to leave a comment.