Let's cut to the chase here: it implies setting a server on your VM and matching its IP to the domain name you chose in the host machine's hosts file.Īs our Vagrant box is almost empty at this point, we need to install a HTTP server on it. How to properly display your work in a browser now? ProvisioningĪlright, so you've got your VM running, you can edit files from outside of it, and access it from the host machine using its private IP. The rest of the process to get your website displayed using the private IP is covered in the next section. Whenever you clone a project containing a Vagrantfile to a machine with Vagrant installed on it, you are at a vagrant up away from having it running locally. On a side note, and to emphasize the usefulness of Vagrantfiles, I think their beauty resides in the fact that all it takes to make the environment available to other developers is to version them with your projects. Be curious and scan through the official documentation, it is well written and I am sure you will find something useful to you. This is it for the options I mainly use I rarely need the rest. Reload your VM and try again: you should now get responses. Open a terminal on your host machine and type the following command:Ĭonfig. Port-forwardingįirst let's run a quick test. The easiest way to achieve this is probably using port-forwarding. Using your host machine's editor to update files on your VM via shared folders is nice, but at some point you will want to admire your work in a browser, which implies for it to have access to your Vagrant box somehow. Let's look into accessing your VM from the host. The Vagrantfiles are written in Ruby, but no Ruby background is required (I don't know much about Ruby myself). I am not going to go through all the options here, only those I most often use. Just know that even if you destroy your box, files under /vagrant remain untouched. I won't explain how to shutdown it just take a couple of minutes to read about the different available options in the doc, they are well explained. You can simply leave your box typing ctrl + d. This is the same Vagrantfile you have just updated: /vagrant is the folder that is shared between the host machine and the VM. Then, download Vagrant at (v1.7.2 at the time of writing), install. If something goes wrong, you don't screw your machine: you destroy your VM instance and recreate it instead.įirst, download VirtualBox at ( "platform packages") and install it. It also permits not to clutter up your computer with tons of different libraries and software that aren't used by every project. The other advantages I see is the fact that one can still use their editor of choice, as Vagrant folders are shared with the host by default. No surprises when pushing the code live, no more "it works on my machine". Ship a Vagrant configuration with each project, and every developer will work on the same environment locally. So what is actually the point? The main argument is the consistency of the environments among developers working on the same project, and more importantly that these environments reflect the production ones. As its support is shipped with Vagrant, we will use VirtualBox, but others exist. It relies on a VM provider, that deals with virtualization itself. Vagrant is a VM manager, in the sense that it reduces the management and the configuration of VMs to a handful of commands. All inside your own machine (which is then called the host). To understand what a Virtual Machine (VM) is, think of an emulator: you install it on your computer so you can then run software that believe they are running in the environment they were designed for. Vagrant greatly simplifies the use of Virtual Machines to spawn development environments in no time (well, it's probably more like no effort than time). Access the host machine when using a private network.In case of trouble, don't hesitate to refer to it. The final result of this tutorial is available as a Github repository. The point of Vagrant is precisely not to have to worry too much about it. This is indeed written from a web developer's standing point, and I will not spend too much time describing how things work under the hood (not that I am an expert anyway). This article shows how to quickly get up and running with Vagrant, to create and use local Virtual Machines as development environments, all with a single command. Heads-up!While Vagrant served me well for years, I do not recommend using it for local development anymore and advise to use Docker instead, for which I wrote an entire tutorial series which I invite you to read. You can also subscribe to the RSS or Atom feed, or follow me on Twitter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |