On windows 10 I have ran my vagrant up and then ssh into my vm successfully. Installed apache2 php5-cli php5 libapache2-mod-php
Now when i access localhost:8080 it is showing me apache default welcome page. How can i access my site in the browser ?
Here are the contents of my Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
# 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
end
This is my current directory structure
You'll need to get your data into the VM and configure Apache to serve that data. For starters, add this to you Vagrantfile (after the confiv.vm.network line):
config.vm.synced_folder ".", "/var/www/html"
It will make your app folder available under /var/www/html on the VM. Apache on Ubuntu serves from that folder by default, so you should be able to see something after doing vagrant reload.
when you edit the configuration file by using vim or any other editor. After that, you have to reload the vagrant and then try to access the localhost:8080
Use the command
vagrant reload
Related
I am using Vagrant on Windows 10.
I have installed centos 7 vagrant box,it is running correctly.
Vagrantfile is like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "dev"
config.vm.hostname = "vagrant-dev"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.3"
config.vm.synced_folder "d:/vagrant_env/www/", "/var/www"
end
I installed nginx in centos 7 vagrant box, and I can access nginx welcome page with ip 192.168.33.3.
I want to access it with domain name,so I configure C:\Windows\System32\drivers\etc\hosts
file in windows:
192.168.33.3 www.example.vagrant //add this line into hosts file of windows
and configure /etc/nginx/conf.d/default.conf file in centos 7:
server {
listen 80;
server_name www.example.vagrant;
//...
}
I try accessing www.example.vagrant on windows host,but it does not work.
what should I do?
There's two better solutions to this:
Use xip.io for your address. In this case http://example.192.168.31.3.xip.io/ will route to your address.
Set up a DNS entry for that which can be resolved. An inexpensive .com or .info test domain at a registrar which makes updating easy (e.g. Amazon Route 53) is always handy for this.
Some programs stubbornly refuse to read entries in /etc/hosts or the equivalent in Windows.
Navigate to 192.168.31.3:8080 in your browser. If you can see your server, then just make your redirect like that: 192.168.31.3:8080 www.example.vagrant
config.vm.network "forwarded_port", guest: 80, host: 8080
At this point you are saying "whatever happens inside Vagrant on port 80, forward it to port 8080 on host machine". You have to communicate with your Vagrant machine on port 8080.
Also your IP is wrong 192.168.33.3 vs 192.168.31.3
I started learning Vagrant and I'm trying to up vagrant machine with hashicorp/precise64 box. I've installed VirtualBox 5.1 on Gentoo and I emerged Vagrant from Gentoo repository. I executed following command in terminal:
pecan#tux ~/vagrant_getting_started $ vagrant box add hashicorp/precise64
==> box: Loading metadata for box 'hashicorp/precise64'
box: URL: https://vagrantcloud.com/hashicorp/precise64
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) hyperv
2) virtualbox
3) vmware_fusion
Enter your choice: 2
==> box: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
box: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box
==> box: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
pecan#tux ~/vagrant_getting_started $ nano Vagrantfile
pecan#tux ~/vagrant_getting_started $ vagrant up
No usable default provider could be found for your system.
Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.
The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.
If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.
and I got above error when I tried to up Vagrant machine.
Vagrantfile content:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "base"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# 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.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.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"
# 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 "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
end
end
vagrant up --provider=virtualbox command returns the below error:
pecan#tux ~/vagrant_getting_started $ vagrant up --provider=virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
Vagrant uses the `VBoxManage` binary that ships with VirtualBox, and requires
this to be available on the PATH. If VirtualBox is installed, please find the
`VBoxManage` binary and add it to the PATH environmental variable.
I'm counting for help!
The Vagrantfile is wrong, it does not contain the correct box information
You can remove the whole folder all together and start with vagrant init hashicorp/precise64 which will create a correct Vagrantfile, then you can run vagrant up (virtual box should be the default provider if not run vagrant up --provider virtualbox)
Fix the Vagrantfile and replace
config.vm.box = "base"
with
config.vm.box = "hashicorp/precise64"
Then you can run vagrant up and it will work.
For my web development, I use a vagrant install to run a local instance of the website with the following config:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network :forwarded_port, host: 4567, guest: 80
config.vm.hostname = "some-website"
config.vm.synced_folder ".", "/var/www/public", :mount_options => ["dmode=777", "fmode=666"]
config.vm.provision :shell, path: "bootstrap.sh", :args => "some-website", privileged: false
end
This website is accessible in the browser on the specified IP.
However, I also have VM's for cross browser testing and these VM's don't have access to the IP address of the Vagrant box.
I need them to connect, because I want to do cross browser testing on that locally running vagrant box.
A couple of StackOverflow searches gave me the option of changing the private_network to a public_network, but then I can't access the IP anymore.
Also adding virtualbox__intnet: true doesn't work.
Would anyone be able to come up with a solution for this? It would be great if I could access the IP from the IE9 VM, directly into the Vagrant VM.
So, to clarify, currently:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can't access Vagrant (VM -!> VM)
What I want:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can access Vagrant (VM -> VM)
As Frédéric pointed out: the private_network is actually accessible from another VM on the same host.
My problem seemed to be WordPress itself and not related to Vagrant or the VM setup.
I am new to to Php/Laravel and VMs world.
I booted up vagrant with this Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "laravel/homestead"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# 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: "192.168.33.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"
# 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 "./devpeople", "/home/vagrant/devpeople"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
I've tried expirimenting using vagrant commands from their documentation, plus modifying the Vagrantfile without success.
What I want is a similar "site mapping" expirience, just like when you edit the Homestead.yaml file. Plus what is supposed to be the default way?
create a folder in your host machine something like
c:/projects/devpeople
Modify your Vagrant file like this
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
or you can change the port like this
config.vm.network "forwarded_port", guest: 80, host: 8081
see below
create a folder in your virtual machine
vagrant up
vagrant ssh
cd var/www
mkdir devpeople
So your virtual machine should have a folder like this
/var/www/devpeople
Then you can put your projects in your host machine
So the Vagrant sync folder will look like this
config.vm.synced_folder "c:/projects/devpeople", "/var/www/devpeople"
Run
vagrant up
and access your development site
localhost:8081
If the folder does not "sync", run
vagrant halt
to restart vagrant
then
vagrant up
You will need to forward ports from within your VM to the host. Here is an example from my Vagrantfile for Payara:
config.vm.network :forwarded_port, guest: 4848, host: 4849
config.vm.network :forwarded_port, guest: 8080, host: 8081
So because I know that Payara uses ports 4848 and 8080 by default, I have forwarded them to similar ports on my host (to avoid clashes).
So if I went to http://localhost:4849 after running vagrant up, I would be redirected to port 4848 within the VM, as though it was running locally.
Looking into the Laravel documentation, it looks like the following ports are the ones you need to make sure are available:
SSH: 2222 → Forwards To 22
HTTP: 8000 → Forwards To 80
HTTPS: 44300 → Forwards To 443
MySQL: 33060 → Forwards To 3306
Postgres: 54320 → Forwards To 5432
The docs imply that this is done by default, though, so you may want to try using them first to make sure.
Well I missed a vital step in the laravel documentation. The proper way to setup your vagrant box is by cloning the "setup" files from the
laravel/homestead repository.
So in order to access the server you simply edit the sites, on the Homstead.yaml file.
I have a Vagrantfile as below running under libvirt. When the box boots, the project directory is mounted under "/vagrant" not "/path/to/source". It works fine on another machine under VirtualBox.
Any ideas? Symlinking /vagrant to the actual place I want the mount is hacky.
vagrant up --debug shows that it isn't even attempting it. The port forwarding works OK though.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "mybox"
file = File.open("#{Dir.home}/.mybox_key", "rb")
key = file.read
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder "./", "/path/to/source/", type: "nfs"
end
If you're running an older version of Vagrant that doesn't support this option (e.g. 1.3.5), it may fail silently instead of trying to setup the NFS share. Ensure you're running at least Vagrant 1.5.1.