Kostas Dimakis
Kostas Dimakis

Reputation: 1153

Vagrant - PhpStorm - Laravel - HTTP Where can I access my local website?

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?

Upvotes: 0

Views: 270

Answers (3)

Kostas Dimakis
Kostas Dimakis

Reputation: 1153

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.

Upvotes: 0

user2338925
user2338925

Reputation:

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

Upvotes: 1

Mike
Mike

Reputation: 4963

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.

Upvotes: 0

Related Questions