1

I'm used to use php -S 0.0.0.0:8080 while developing, because it saves me some time configuring a real web server. Until today I didn't miss anything about it, but now I need to develop a function that uses subdomains.

I must access http://foo-bar.localhost:8080 and make php see the request, because I'm trying to implement this.

Also, foo-bar is dynamic (like the language subdomain in the documentation of Yii2 I linked) so I need php to be able to handle all subdomains of localhost.

Is that possible? How?

alexandernst
  • 14,352
  • 22
  • 97
  • 197
  • 1
    This isn't a question of the http server, be it builtin or not, but of your network setup. If the hostname is resolved correctly, then the requests reaches the server. So check what that hostname `foo-bar.localhost` is resolved to. Adjust that in your systems networking configuration, if required. – arkascha Jun 27 '15 at 10:25
  • @arkascha I thought about this, but it is not working. I added `127.0.0.1 foo-bar.localhost` to my `hosts`file, but php doesn't see the requests. `ping` is able to resolve. – alexandernst Jun 27 '15 at 10:26
  • Ping is mostly useless for networking diagnostics. Use telnet instead: `telnet foo-bar.localhost 8080`. Does it connect or not? What is the reply? – arkascha Jun 27 '15 at 10:28
  • @arkascha Nope, telnet isn't resolving. How should I route it? – alexandernst Jun 27 '15 at 10:29
  • What _is_ the exact result? – arkascha Jun 27 '15 at 10:30
  • @arkascha $ `telnet foo-bar.localhost:8080 telnet: could not resolve foo-bar.localhost:8080/telnet: Name or service not known` – alexandernst Jun 27 '15 at 10:30
  • @arkascha Oh, sorry, there was a typo in my command. It does resolve actually: `$ telnet foo-bar.localhost 8080 \n Trying 127.0.0.1... \n Connected to foo-bar.localhost. \n Escape character is '^]'. \n ^CConnection closed by foreign host` – alexandernst Jun 27 '15 at 10:31
  • Ah, that is better, you realized yourself, great! That looks like an http server, actually. No idea why it disconnects. Works for me locally. – arkascha Jun 27 '15 at 10:32
  • @arkascha So, telnet is able to resolve, which means that PHP should see the requests, but it doesn't. What could be wrong? – alexandernst Jun 27 '15 at 10:34
  • As said: works for me locally. I checked and I can use a hostname ("subdomain") with the builtin php server. Maybe you just have a caching issue in your browser? Or your browser resolves different? Maybe using a proxy? – arkascha Jun 27 '15 at 10:35
  • I would make a variable out of `http://foo-bar.localhost:8080` and point it to local server during development – hek2mgl Jun 27 '15 at 10:37
  • @arkascha Indeed. It was Chrome, once again, trying to be too smart, caching the address of "already resolved" urls. – alexandernst Jun 27 '15 at 10:41
  • So things work all right now? Great! You made it! BTW: installing an apache http server is a single command. Sure that is too much hassle? :-) – arkascha Jun 27 '15 at 10:42
  • @arkascha Yup, everything works now :) Thank you! The install part is easy. The config is what takes me too much as I'm changing projects every few hours. Laziness is another factor too... – alexandernst Jun 27 '15 at 10:45

0 Answers0