![]() Do note, any time you make a change to the Vagrantfile and the virtual machine is already running, you will need to run a vagrant reload or vagrant provision to actually make the changes take effect. With this change, we should be able to launch a browser and see the Nginx welcome page right away. Note the updated line of config.vm.network “forwarded_port”, guest: 80, host: 8080, id: “nginx” below. We can make one additional configuration change to the Vagrantfile so that we can browse to our newly installed Nginx web server. It might be nice to also test this from a browser, so let’s set up port forwarding next in order to do this. Check it out, we get the raw html right in the terminal window. We won’t be able to use a browser just yet, but we can fetch the index.html page right from the console via wget -qO- localhost. Note that it is running as we see here via the service nginx status command. We can now vagrant ssh into the guest operating system and have a look at the nginx service. As we can see in this screenshot, as part of the process of the VM coming online, Nginx is being fetched from a remote server and installed for us. In addition to this, since we added a shell script to the Vagrantfile, Vagrant will go ahead and execute anything in that script automatically. This will kick off the process of Vagrant building our virtual machine for us. A quick inspection indicates they look good.Īt the command prompt, we are ready to type vagrant up. ![]() On the host operating system, let’s make sure that both the Vagrantfile and the provision.sh file look correct. ![]() Do note, this file lives in the same exact directory as the Vagrantfile itself. Note we add three simple commands of apt-get -y update, apt-get -y install nginx, and service nginx start to the file and save it. If we were to install Nginx manually, these are the exact commands we would need to run in order to get the Nginx software installed and running. nfigure(2) do |config|Ĭonfig.vm.provision "shell", path: "provision.sh"Īt this point, Vagrant knows there is a shell script involved, but we need to actually put some commands into the script file itself in order for it to do anything. Note the addition of config.vm.provision “shell”, path: “provision.sh”. Basically with that new line added we tell Vagrant that we are going to use a shell script for provisioning, and where to find said shell script via the path attribute. In order to instruct Vagrant to make use of a shell script, we must adjust the Vagrantfile to how it looks in this snippet. One option is to make use of a shell script. Since we would like Vagrant to handle the task of installing Nginx on the virtual machine for us, we need to find a method to do this. Instruct Vagrant to use a shell provisioner We can do this in the same extension viewer as the previous step.īehold! The Vagrantfile in all of it’s syntax highlighted glory! While we are at it, why don’t we add a super cool looking theme to the editor? This Material Theme is one of the most popular for Visual Studio Code, so let’s go ahead and install that. After that, all we have to do is click install. In this screenshot, we located it by clicking on View->Extensions, and then searching for Vagrantfile. In this episode, we are making use of Visual Studio Code, and it turns out there is an extension you can add to the IDE in order to enable syntax highlighting of the Vagrantfile. The Vagrantfile is written in Ruby, it has no extension, however – so most times you will not see any syntax highlighting when editing it. As we can see in this screenshot we make use of mkdir nginx, cd nginx, and vagrant init hashicorp/precise32 -minimal. This will give us a brand new Vagrantfile with a minimal configuration base. Once there, we will go ahead and run the command vagrant init hashicorp/precise32 –minimal. ![]() This leads to better control over our environment, and easier collaboration with others.įrom our home directory, we’ll make a new directory named nginx and then cd into it. They won’t have to fiddle with manual installation of software, it is all scripted out for them. We want to be able to share our Vagrantfile with another developer or administrator, and all they need to do is type vagrant up. Of course, we could go into the VM and manually install nginx process via SSH, but that kind of defeats the purpose of Vagrant. This time, however, we are going to add some shell provisioning to the Vagrantfile in order to automatically install the NGINX web server on our new virtual machine. In this vagrant tutorial, we’re going to create a new development environment using the precise32 box as we have done already. Now that we have learned the basics of how to work with Vagrant, let’s now go a little further into working with the fundamentals in Vagrant.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |