PhpStorm + Vagrant + Symfony2 - php

I want to display Symfony2 page using vagrant box.
If i turn on vagrant box (vagrant up), and use by ssh command "php app/console server:run"
Then i see info " Server running on http://127.0.0.1:8000 "
and if i go to the website "192.168.33.10" or "127.0.0.1" or "127.0.0.1:8000" on host machine, Then i don't see symfony2 site.
Question: How is correctly configuration the vagrant file, that allow me see symfony2 site ?
Its keys lines in my vagrant file .
....
config.vm.box = "symfony-v0.2.0"
config.vm.network "forwarded_port", guest: 8000, host: 80
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "public_network"
config.vm.synced_folder "./", "/var/www/"
....
Add informations:
==> default: Mounting shared folders...
default: /var/www => C:/Users/Wojtek/PhpstormProjects/DragonisProject/Symfony2Project
default: /vagrant => C:/Users/Wojtek/PhpstormProjects/DragonisProject/Symfony2Project

Delete line config.vm.network "private_network", ip: "192.168.33.10" from Vagrantfile.
Then start server server as php app/console server:run 0.0.0.0:8000 it will listen to all ip addresses and access it as http://localhost because you have port 8000 forwarded to port 80 on host machine.

1) Make sure you set your local host file to point your site to the correct vagrant IP (192.168.33.10), if applicable. Otherwise just use the IP directly.
2) If your vagrant instance is running, the issue is likely due to your apache conf within the vagrant box.
Make sure you have the proper Apahce/nginx vhost in place for your site.

Related

Vagrant scotch box not working

I installed vagrant 2.0 with Virtualbox on a Windows 7.
I followed the https://box.scotch.io/ guide but and I cannot access the webserver at http://192.168.33.10:8080
I entered the box via ssh and says that apache2 is not installed and neither is php. They should be, right?
My VagrantFile
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "scotchbox"
config.vm.synced_folder ".","/var/www", :mount_options => ["dmode=777", "fmode=666"]
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
end
you do not need forward_port if you use a private network, when you have a static ip, you will reach the server directly using the IP; or you could with the forward port, but certainly not a mix of your VM static IP and the forwarding port to your host machine; with your setup either http://192.168.33.10 or http://127.0.0.1:8080 would work, but I'd just recommend to remove the forward port and just use the VM IP
you dont need config.ssh parameters, just login with the ssh key.

Ratchet WebSocket won't work over Vagrant machine

I have a WebSocket server using Ratchet (literally the example app). I'm serving it to localhost:8080 on my Vagrant machine (which is a CentOS 6) and trying to connect to it through the private network IP set in the Vagrantfile 192.168.33.10.
I'm getting a connect ECONNREFUSED 192.168.33.10:8080 (the uri is ws://192.168.33.10:8080/chat).
I already exposed the port config.vm.network "forwarded_port", guest: 8080, host: 8080.
I've tried serving the server (inside vagrant) to localhost, 127.0.0.1 and 192.168.33.10, but the client still can't connect.
It works fine outside of Vagrant using localhost on both client and server.
What am I missing?
If you bind the app to localhost there is no way you can access it via 192.168.33.10, hence port forwarding won't work either.
You need to make your app to listen on 192.168.33.10:8080.
Also add the guest's IP address to the Vagrantfile:
config.vm.network "forwarded_port", guest_ip: "192.168.33.10", guest: 8080, host: 8080

Cannot access site from host machine on a vagrant virtual machine

I setup a nginx+mysql puphpet/vagrant image, with a virtual host "test.com". I mapped test.com to 192.168.56.101 on the host machine, and put an index.php file inside /var/www/test.
However, when I try opening the browser at the address test.com on the host machine I get no response. I feel like I'm missing something really simple, because I can ping 192.168.56.101. I also checked nginx logs on the virtual machine, but they are empty. Any clues where the problem might be? Am I not supposed to use it this way? I can ssh into vagrant just fine, and also I can access the mysql db.
In your Vagrantfile, you need to forward the port to your host machine.
For example map port 80 of the Vagrant machine to port 8080 of the host machine.
config.vm.network "forwarded_port", guest: 80, host: 8080

Cannot make outbound HTTP Requests from vagrant VM

I am unable to connect to the internet from within a Vagrant virtual machine I have set up.
For example, at the root, when I type:
curl http://google.com
It fails with the message:
curl: (6) Couldn't resolve host 'google.com'
I'm not sure if it's a firewall setting, although as far as I know I have not created any firewall rules for port 80 or any other port.
Here is the relevant section of my Vagrantfile. If there is any other information I can provide please let me know in the comments:
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Let Vagrant manage the hostname at boot
config.vm.hostname = "devbox"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network :forwarded_port, guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network :private_network, ip: "10.0.0.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network :public_network
# Create a public network with a given hardware address. You can
# configure your DHCP server (on your router) to assign a particular IP
# address to the VM. Update your hosts file accordingly.
# config.vm.network :public_network, mac: "0a00251010101"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
#config.vm.synced_folder "vagrant/logs", "/logs",
# owner: "root", group: "root"
# Base box to use with Virtualbox provider
config.vm.box = "debian-7.0.0-amd64-base"
config.vm.box_url = "http:/mysite.com/debian-7.0.0-amd64-base.box"
This looks like a DNS configuration issue. Do a nslookup google.com and see what the result is.
Try to add the following block in your Vagrantfile, set --natdnshostresolver1 to on so as to force the VirtualBox NAT engine to intercept DNS requests and forward them to host's resolver
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
BTW: Without vagrant reload, you can directly look into the /etc/resolv.conf inside the VM, can manually set it to the DNS server of your network, most likely it'll work fine.

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.

Categories