0
votes

I am using puphpet.com tool to set up Vagrant boxes.

Now , I am able to ssh to it and open the IP on the browser but I can not get to access the VHost I set up earlier through puphpet.

I have edited my hosts file (/etc/hosts ) "using OSX" to serve the IP 2.168.56.101 to lab.dev. Now it works fine but I can not access the virtual machine on the guest machine !!!!.

I am using PHP Laravel framework and I need to access the server name which points to /var/www/lab.dev/public/. I would appreciate very detailed answer as I am really new to all of this

1
I'm not sure if I understood the question correctly, but maybe try vagrant ssh?lozadaOmr
i can ssh to the vagrant box , what i want is to access the vagrant vhost . see , i have set up a vhost inside the vagrant box , what i want is to access the vhost using it's server name "for example lab.dev" from the host "my mac" ... sorry english is not my native languagemunzx

1 Answers

0
votes

Detailed Instructions

  1. Visit PuPHPet.com to build your Vagrantfile.
  2. Configure your Shared Folder Pairs. This is under "Deploy Target > Locally".

    Let's assume this directory structure on your OS/X machine:
    /Users/unrivaled/Documents/laravel-project     (project files go here)
    /Users/unrivaled/Documents/laravel-project/public     (the web root files)
  3. Folder Source represents the location on your main computer (the "host" operating system), where your source files reside; for example: /Users/unrivaled/Documents/laravel-project The Folder Source must be on your OS/X machine, exactly where your Laravel files are.

  4. Folder Target represents the location on your virtual computer (the "guest" operating system), where you want Vagrant to make them visible to the web server; for example: /var/www/lab The Folder Target can be anywhere that Apache or Nginx, in the virtual machine, can reach it.

    Folder Source (local machine) == Folder Target (virtual machine)
    /Users/unrivaled/Documents/laravel-project (local machine) == /var/www/lab (virtual machine)
  5. Configure your web server. Your Server Name can be anything you want; in this example, let's use "lab.dev". Configure your Server Alias; in this case, use "www.lab.dev." Your Server Name (or an alias) must match your entry in your /etc/hosts file; see below. Configure your Document Root. This is the folder on your virtual machine where your website files will go and the files that will be served by Nginx or Apache. This value must be at, or below, the Folder Target defined from Step 4; for example, /var/www/lab/public.

    Notice in the example how we are giving the web server access to /var/www/lab/public? This actually refers to /Users/unrivaled/Documents/laravel-project/public on your local OS/X system, thanks to the "Shared Folder Pairs" configured in Step 2., above.
  6. Generally, configure everything else in PuPHPet as you see fit.

  7. Run vagrant up to get your virtual machine up and running. If it doesn't work at this stage, you need to resolve any problems before going on.
  8. Determine your virtual machine's IP address. Use vagrant ssh to log into the virtual machine, and then ifconfig should work for this. Do not rely on the IP address defined in PuPHPet. Your virtual machine provider will likely override this value, and you need to know the actual, in-fact IP address.
  9. On your main host computer (not the virtual machine), edit your /etc/hosts file: sudo nano /etc/hosts, adding the server's IP address, followed by the Server Name (or a Server Alias) defined in Step 5, above.

How It Works


Once you have a working web server using the settings in this example, you can view your website by going to lab.dev. Your browser in OS/X will resolve lab.dev to the proper IP address of your server by way of the /etc/hosts file. It then requests your web page from that IP address, where the server matches the requested resource, "lab.dev," to the appropriate Server Name or Server Alias that matches. The files in the Document Root for that server name (/var/www/lab/public) will be processed by the web server.

In summary, your server's IP address in the local /etc/hosts file matches your server's IP address in the virtual machine; your server's name in the local /etc/hosts file matches your Server Name (or Server Alias) in the web server on the virtual machine; the path name to your project source files on your local computer (Folder Source) maps to the Target Directory on the virtual machine; and finally, a subdirectory of that target directory (public) corresponds to the Document Root for the web server.