Connecting to Your Web Server

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:05
    with Emma Jane Westby
  • 0:08
    We've now got our web server up and running.
  • 0:11
    But we haven't actually tried to connect to it in a browser.
  • 0:14
    To do this, we'll need to forward the port from the guest machine
  • 0:19
    back to our host machine.
  • 0:22
    To do this, we need to configure port forwarding in the Vagrant
  • 0:24
    file, reload the Vagrant instance so that the port forwarding takes
  • 0:29
    effect, log into our web server, and confirm
  • 0:32
    that Apache is running-- hint, it won't be.
  • 0:35
    And then in a web browser we can load up our new server
Loading ...

Connecting to Your Web Server

Loading...

In order to "find" our virtual server in a Web browser, we need to make a map between the two host machine, and your guest server. To do this we will use a technique referred to as port forwarding. This allows any communication from the host machine (your Web browser) to be automatically redirected to the appropriate location on your guest machine (the Web server). Fortunately this is very simple to do. In this lesson we are going to map port 4567 traffic on the host machine, onto the standard Web port, 80, on the server. This means when you access Web traffic at http://localhost:4567, it will be automatically redirected to Apache on your server. It's almost like a sleight of hand magic trick where a rabbit appears in a hat, but way cooler.

Lesson Outcomes

By the end of this lesson you will be able to correctly configure your server's network settings so that Web pages can be viewed in a browser on your host machine.

Lesson Summary

  1. Edit your Vagrantfile (Vagrant configuration file to set the following properties:
  2. Configure port forwarding
    config.vm.network "forwarded_port", guest: 80, host: 4567
  3. Reload the vagrant instance.
    $ vagrant reload
  4. Log into the server, confirm Apache is running. (Hint: it's not running.)
    $ curl 'http://localhost:80'
  5. Start Apache.
    $ /etc/init.d/apache2 start
  6. In a Web browser, navigate to:
    http://127.0.0.1:4567
    (Hopefully) It works!

Gotchas

This can sometimes be the tricky bit, especially if you already have a lot of custom network configuration. If this lesson doesn't work for you, you will need to do an audit of your system to find any software which might be interfering with the connection. We're going to limit ourselves to one VM running at a time (all the same ports). This is mostly because of the hardware limitations I expect you'll have. If your machine is more powerful, great! But we're not covering it in this video series.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.