Webserver not listening to ports - php

Problem
I've recently found out that PHP has a built-in webserver which can be used for development purposes. Starting the server with the address "127.0.0.1" and the port "8080" works without any problems and my requests are handled properly. However, if I dare to use the address "localhost" with the same port, the webserver doesn't handle any requests.
Specs
Windows 10 64-Bit
Php 64-Bit Thread-Safe installed
MongoDB installed (Not running)
IIS Server installed and running
MariaDB installed (Not running)

Name resolution for localhost is handled by your DNS server which is likely resolving it to the IPv6 address ::1.
If you run:
php -S 127.0.0.1:8080
The webserver is running on the IPv4 address but localhost resolves to the IPv6 address.
So you can either use 127.0.0.1:8080 in the browser address bar.
Or force the address by un-commenting the following line from C:\Windows\System32\drivers\etc\hosts:
# 127.0.0.1 localhost
Or bind the webserver to the IPv6 address (this is what I do):
php -S localhost:8080

Related

how to access virtual host set in vagrant

I am having debian vagrant. I have done virtual host configuration in its apache as servername https:local-dev02.sitename.com. And used in my windows machine host file 127.0.0.1 local-dev02.sitename.com.
I can access my site in windows' browser as https://local-dev02.sitename.com:8443/.
But I am unable to do
ping https://local-dev02.sitename.com
OR
curl https://local-dev02.sitename.com
OR
wget https://local-dev02.sitename.com
It is only possible to ping a hostname or IP address, but not an URL. So you need to put off the protocol like so
ping local-dev02.sitename.com
To reach your hosts via the hostnames, please add the IPs and hostnames to the /etc/hosts file.

Google cloud shell problem with PHP built in server - could not connect to Cloud Shell on port 8080

I can't get to work my simple index.php file on Google cloud shell. I start my server with command php -S localhost:8080 -t test/. Before that I navigate just before test folder. I click Web preview in upper right corner and get error: Could not connect to Cloud Shell on port 8080 What could be the problem?
After hours of working, and reseting... I just change from php -S localhost:8080 -t test/ to php -S 127.0.0.1:8080 -t test
In Cloud Shell localhost resolves to both IPv4 and IPv6 addresses:
$ head -3 /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
It appears that when this is the case, PHP's builtin web server only binds to the IPv6 address; however, Cloud Shell web preview connects to the IPv4 addresses. Your solution to bind directly to the IPv4 loopback interface (127.0.0.1) is probably the best, for now.

Can't connect Websocket when using vagrant envirionment

I'm using Vagrant box using puphpet, the environment is PHP 5.5 + ubuntu 12.04 + apache + mysql. My Vagrant VM ip: 192.168.11.11, local machine hosts points to 192.168.11.11 reactphp.dev, and it works.
And, I'm using this code: https://github.com/muuknl/phprealtimechat to test websocket.
Then I visit reactphp.dev in my Chrome browser, and I start server script using: php bin/server.php, and after I type in the username I just got the error:
WebSocket connection to 'ws://192.168.11.11:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
It works well when I changed the websocket ip to `ws://127.0.0.1:2000/', but why it does not work if I change to my VM's ip address?
It's been a while I haven't used PuPHPet, but when I had troubles connecting through the port (minus port 22), I've had to issue the command sudo ufw disable in the vagrant machine.
If uwf isn't the managing firewall of your vm, try sudo service iptables stop, or sudo iptables -F.
Perhaps they've changed the behavior since then, but it's still good to try.
The SSH tunnel (over the opened port 22) might allow you to access the local port 2000, which is proxified over. The actual port 2000 of the VM might be limited due to firewall.
Try it, and tell me if this works. If not, I'll dig in deeper.

Vagrant VM shows "SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1" in browser when navigating to "127.0.0.1:2222"

Why ?
I've set up an extremely simple server, like 50 times before, but this is my first try with Vagrant.
Current behaviour:
Vagrant VM shows "SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1" in browser when navigating to "127.0.0.1:2222". 2222 is the standard port for the first Vagrant VM.
Expected behaviour:
127.0.0.1 should show the index.html/php of the apache2 web folder.
When you run a vagrant up, you'll see a message showing [default] Forwarding ports... -- 22 => 2222 (adapter 1). ssh is listening on port 22 on your VM, you can ssh to port 22 (default) from your local box to connect to the VM; but if you have configured the VM to allow external access, then anyone else on another machine needs to use your IP address but port 2222 to connect to the VM.
This might be useful if you ran the VM on a box in work, but wanted to be able to access it when you were at home, or in a client's office, or even from another machine in your work's network.
Using a browser to connect to the SSH port 2222 will redirect to port 22 on the virtual box, but it's ssh that's listening on this port; and a web-browser isn't the right tool for an ssh connection.
Personally I use putty as my ssh client, but with vagrant you can also issue a vagrant ssh after starting the virtual machine.
Additional
The values of port forwarding
If you set
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 443, host: 8443
in your vagrantFile, and you've allowed public access to the VM, then you can access the webserver on the VM from home, a client or another box in your work network by pointing the browser to port 8080 (or 8443 for https) rather than the more normal default ports 80 and 443... which can be particularly useful for running demos from a laptop that you can take to a client site while your VM is running on a bulky desktop under your desk in work
MarkBaker's answer solves the problem, but Vagrant 1.2.7 (and newer) needs this syntax:
# Forward guest port 80 to host port 80
config.vm.forward_port 80, 80
The full Vagrantfile (you can find it where your box file is) would look like this:
Vagrant::Config.run do |config|
# Forward guest port 80 to host port 80
config.vm.forward_port 80, 80
end
This example would route a request on port 80 (standart port) in your host OS to port 80 in your Vagrant VM. The result is, http://127.0.0.1 in the host browser will show you the localhost of the VM.
When working with multiple VMs please notice that you should use a unique port for every VM.

Zend Server CE, After Uninstall, localhost doesn't work

This is odd...
I installed Zend Server to test it out. Turns out I don't like it and I wanted to go back to MAMP. But after the Zend Server CE uninstall, "localhost" no longer works. I can only access MAMP from 127.0.0.1
Frustrating and I'm not liking it at all.
Any ideas?
hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 mydomain.loc www.mydomain.loc
nslookup says:
Server: 64.59.160.13
Address: 64.59.160.13#53
Non-authoritative answer:
Name: localhost
Address: 127.0.0.1
I was told by a college that sometimes the only thing you can do to wake up port 80 on the Mac is to enable the built in web server and then disable it again.
So I did that and all is well.
you mention 127.0.0.1 which is a IPv6 address. Many (all?) modern operating systems are configured to resolve localhost using IPv6 to ::1. My assumption would be that your MAMP setup is not listening via IPv6. Try opening http://[::1]/ if that works there is an error in our resolve configuration, if not (what I expect) you have to configure your web server to either lsiten to ::1 or any device.
This can be done in httpd.conf using
Listen 80
to listen on all devices, port 80 or
Listen [::1]:80
to listen to localhost via IPv6 only. Mind not having conflicting VHost entries etc.

Categories