Need Help Configuring Preview to Display PHP Page (502 Bad Gateway variant)
PhpStorm 2019.2.4, Build #PS-192.7142.41, built on October 30, 2019 | macOS 10.15 (Catalina)
MAMP Pro 5.5.1 (17995) | PHP v7.2.21 | XDebug 2.7.2 | Firefox 70.0.1 (64-bit)
I just installed PhpStorm fresh on a brand new laptop and am going through the initial configuration woes.
Trying to take a simple .html file that's been renamed to .php and preview it by clicking on the little browser icon in the source code window.
Firefox opens as expected, and I'm taken to the following URL showing a 502 Bad Gateway message:
http://localhost:63342/myproject/index.php?_ijt=grupu5172jtrodhhc5qfoobar9
Clearly, I'm missing something.
So far, I have:
- Installed MAMP Pro, ensured Apache and MySQL are running (though this shouldn't be necessary, as I'm trying to use PhpStorm's built in webserver), selected PHP v7.2.21 (to match my server), and validated I can invoke PHP from the command line
- Installed the Xdebug Debugger extension
- Set the CLI Interpreter, confirming it sees PHP version 7.2.21 and XDebug 2.7.2:
PHP Executable: /Applications/MAMP/bin/php/php7.2.21/bin/php-cgi
Debugger Extension: /Applications/MAMP/bin/php/php7.2.21/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so - Set a Deployment to type "In place", and checked the mappings' Local Path is correct
- Can see in the PHP-CGI Server tab it says:
/Applications/MAMP/bin/php/php7.2.21/bin/php-cgi -e -b 127.0.0.1:56162 - Read a lot of documentation, blog posts, and StackOverflow ...but have not found a solution, noting that there is no mention of 502 or Bad Gateway in a Troubleshooting section of the documentation according to the manual's search box.
- Verified if I rename the .php file back to .html (remember, there's no PHP code in it yet!), the page loads just fine.
What I'm expecting to happen is the local PhpStorm built-in web server to invoke MAMP's php-cgi and render the web page.
Any thoughts as to what I've overlooked? It's got to be simple and obvious.
Please sign in to leave a comment.
Follow up -- running this from the command line, correctly renders the page:
$ /Applications/MAMP/bin/php/php7.2.21/bin/php-cgi ~/PhpstormProjects/myproject/index.php
So I'm pretty sure PhpStorm's built in browser isn't executing the php-cgi script.
Decided to take a look in idea.log; saw something unexpected (though not sure if related):
2019-11-04 18:05:29,240 [12475476] ERROR - ains.io.fastCgi.FastCgiService - PhpStorm 2019.2.4 Build #PS-192.7142.41
2019-11-04 18:05:29,240 [12475476] ERROR - ains.io.fastCgi.FastCgiService - JDK: 11.0.4; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2019-11-04 18:05:29,240 [12475476] ERROR - ains.io.fastCgi.FastCgiService - OS: Mac OS X
2019-11-04 18:05:34,244 [12480480] ERROR - ins.io.ChannelExceptionHandler - minimumReadableBytes: -1006 (expected: >= 0)
java.lang.IllegalArgumentException: minimumReadableBytes: -1006 (expected: >= 0)
at io.netty.util.internal.ObjectUtil.checkPositiveOrZero(ObjectUtil.java:66)
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1433)
at io.netty.buffer.AbstractByteBuf.skipBytes(AbstractByteBuf.java:979)
at org.jetbrains.io.Decoder.getBufferIfSufficient(Decoder.java:117)
at org.jetbrains.io.fastCgi.FastCgiDecoder.messageReceived(FastCgiDecoder.kt:58)
at org.jetbrains.io.Decoder.channelRead(Decoder.java:24)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1421)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:697)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at java.base/java.lang.Thread.run(Thread.java:834)
Hi there,
Sadly, PhpStorm's built-in web server can give 502 errors for a perfectly fine & valid requests for no apparent reason: https://youtrack.jetbrains.com/issue/WEB-31859
I suggest to use proper web server (you have MAMP, so why not use Apache from there?) .. or PHP's built-in server (if your project can work with such setup) -- https://www.php.net/manual/en/features.commandline.webserver.php (in PhpStorm it can be used via "PHP Built-in Web Server" type of Run/Debug configuration)
To use MAMP -- define deployment entry and specify URL there, then mark it as Default for this project. Now "Open in Browser" kind of actions will use URL from there. If you do not do that then IDE will keep use PhpStorm's built-in web server URLs.
P.S. You may need to edit URLs or delete existing Run/Debug Configurations -- they may remember previous URLs.
>Set the CLI Interpreter, confirming it sees PHP version 7.2.21 and XDebug 2.7.2:
>PHP Executable: /Applications/MAMP/bin/php/php7.2.21/bin/php-cgi
I suggest pointing to just "php" and not "php-cgi"
Andriy Bazanov -- I've tried both, with identical results, but agree php is the better option all things equal.
As for WEB-31859, that's somewhere between sad and frustrating. It's curious that it certainly works for web pages, but PHP causes issues ...especially since PhpStorm is for designing PHP. This makes me wonder if something is just misconfigured somewhere. The code exception does sound like a much larger issue though. (And it's really been that way for a year? Wow.)
You're absolutely correct in that using MAMP to deliver the content works perfectly fine -- which is the solution I had been using, though just toggling between the IDE and the web browser manually. I find it annoying not being able to use the IDE itself right out of the box.
I tend to have this problem with nearly all JetBrains products in that they jump into an IDE that has no working default and the mandatory things one needs to set up are scatter all over. What I'd love to see is something similar to $ brew doctor where the IDE runs a diagnostic and tells you if it's ready to go, if there are any conflicts, or what specific steps need to be done next to get to a working state. #WishfulThinking
I appreciate the help with the trickery to coerce the IDE into using an external system. Much appreciated.