2

Take a domain name like:
development.mysite.com

I want to setup a vhost with Vagrant that would allow me to access this location in my browser.

From what I can tell, it won't let me use port 80, so even if I change my hosts file to something like:

127.0.0.1 development.mysite.com

It still won't find it.

Does anyone have an idea?


UPDATE

VagrantFile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "hashicorp/precise32"

  # Networking
  config.vm.network "forwarded_port", guest: 80, host: 8000
  config.vm.network "private_network", ip: "192.168.33.10"

  # Synced folders
  config.vm.synced_folder ".", "/var/www"

  # Provisioning
  config.vm.provision :shell, :inline => "apt-get update --fix-missing"

  config.vm.provision :shell do |shell|
    shell.inline = "mkdir -p /etc/puppet/modules;
                    (puppet module install example42/puppi; true)
                    (puppet module install example42/apache; true)
                    (puppet module install example42/php; true)
                    (puppet module install puppetlabs/stdlib; true)
                    (puppet module install puppetlabs/mysql; true)
                    (puppet module install saz/vim; true)"
  end

  config.vm.provision "puppet" do |puppet|
    puppet.facter = {
      "fqdn" => "development.eatologie.com",
      "hostname" => "www",
      "docroot" => '/var/www/html/'
    }
    puppet.manifests_path = "puppet"
    puppet.manifest_file  = "site.pp"
  end
end

Puppet site.pp

###########################
# Eatologie Puppet Config #
###########################
# OS          : Linux     #
# Database    : MySQL 5   #
# Web Server  : Apache 2  #
# PHP version : 5.4       #
###########################

# Vim
class { 'vim': }

# Puppi
class { 'puppi': }

# Apache setup
class { "apache":
    puppi        => true,
    puppi_helper => "myhelper",
}

apache::vhost { $fqdn :
    docroot => $docroot,
    server_name => $fqdn,
    priority            => '',
    template            => 'apache/virtualhost/vhost.conf.erb',
}

apache::module { 'rewrite': }

# PHP Extensions
class {"php":}

php::module { ['xdebug', 'mysql', 'curl', 'gd']:
    notify => Service['apache2']
}

# MySQL Server
class { '::mysql::server':
  root_password    => 'abc123',
}

mysql::db { 'eatdb':
    user     => 'admin',
    password => 'abc456',
    host     => 'localhost',
    grant    => ['all'],
    charset => 'utf8',
}

# Eatologie Setup

file { $docroot:
    ensure  => 'directory',
}

$writeable_dirs = ["${docroot}cache/", "${docroot}cache/css/", "${docroot}cache/css/js/"]

file { $writeable_dirs:
    ensure => "directory",
    mode   => '0777',
    require => File[$docroot],
}
Kerry Jones
  • 21,806
  • 12
  • 62
  • 89

1 Answers1

4

As far as I can see, this is the relevant part in your Vagrantfile:

# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "private_network", ip: "192.168.33.10"

It means that your Vagrantbox is accessible at ip 192.168.33.10 and port 8000. So, your hosts file should say

192.168.33.10   development.eatologie.com

instead of

127.0.0.1   development.mysite.com

With that change, you should be to access your site at development.eatologie.com:8000

For more info, also take a look at the Vagrant documentation pages for forwarded ports and private networking. For the private networking part take into account that, if you assign a static IP to your Vagrant box (as you did in your setup), you have to be sure the IP is not taken by another device on your local network.

Sidney Gijzen
  • 1,931
  • 3
  • 24
  • 27
  • Okay, so I got it working at development.eatologie.com:8000, but I don't want to have to specify a port, just the FQDN, I can't seem to find a way to do that. – Kerry Jones Jun 22 '14 at 20:58
  • Try commenting out the forwarded_port line and do a `vagrant reload`. Are you then able to access your site by FQDN only? I checked my own vagrantfile, but I have no forwarded_port defined... – Sidney Gijzen Jun 22 '14 at 22:23
  • Didn't work, what version of vagrant? I am running 1.6.3 – Kerry Jones Jun 22 '14 at 23:34
  • Also 1.6.3. Can you also post your vhost template? (apache/virtualhost/vhost.conf.erb). Perhaps the VHost is listening on another port... – Sidney Gijzen Jun 23 '14 at 18:58
  • 1
    I found the answer -- it isn't possible with vagrant with these ports. https://docs.vagrantup.com/v2/networking/forwarded_ports.html - the ports must be over 1024, so there is no way to make it listen on port 80. I found that if I use something like Fiddler2 I can make it work, otherwise I just have to deal with the port number. – Kerry Jones Jun 23 '14 at 19:42