Setting up Development Environment with Vagrant
In this tutorial, we will demonstrate how to install Vagrant on multiple operating systems.
What is Vagrant?
Vagrant is a tool for managing virtualization and virtual machines in a single workflow. We can describe it as a wrapper for a hypervisor like KVM, VirtualBox, or VMWare. This allows a team to use the same development environment when creating an application on a dedicated server production environment. We can then simply share vagrant files with others across the same platform.
In the following sections, we will cover the installation of Vagrant on:
- Windows 10
- Linux CentOS 7
Regardless of the type of OS, we can use vagrant with any of the hypervisors but for our use case, we will be using Vagrant with VirtualBox.
- Git For Windows
Installing Git for Windows
To install vagrant on our Windows server, we need to install Git for Windows from this link.
We will download the needed .exe file for windows by clicking the windows icon. After installing Git, many of the options can be left set to the defaults, but we need to pay close attention to following options.
- Git from the command line and also from 3rd-party software
- Use the OpenSSL library
- Checkout as-is, commit Unix-style line endings
- Use MinTTY
After the Git installation has completed, we can proceed with downloading and installing VirtualBox to use as our hypervisor.
Installing VirtualBox on Windows
We mentioned at the beginning of our tutorial that Vagrant acts as a wrapper for our hypervisor. Next, we need to install the hypervisor from this link.
- Download the virtual box from the link above.
- Install it following the images below
- Click Windows Hosts to start downloading.
- Once the installation has started, we can leave all the default options in place.
Once the VirtualBox installation has completed, we need to install Vagrant as the final component to begin using it on our Windows server.
Installing Vagrant on Windows
To use Vagrant, we need a version of Vagrant installed on our Windows server. We can download it here.
- Click on the link above and then download version 2.2.7.
- Select the Windows 32-bit or 64-bit version depending on your server type.
- Once the download completes, double click the .exe file to begin the installation and then follow the directions below.
Click the Next Button to proceed.
Agree to the license and click next.
Select the installation folder and then click Next.
Now we are ready to complete the installation. Click the Install button to proceed.
After Vagrant has installed, we will need to restart Windows to apply the changes. Once the installation completes, we can start using Vagrant on our Windows computer.
In this part of the tutorial, we will be installing Vagrant on a CentOS 7 server. Basically, we have several options available to us, but in this case, we will take a bit of a different approach by installing Vagrant using the official RPM package from this link.
Installing Vagrant on CentOS 7
- Login to your Linux CentOS workstation and open the terminal.
- Check the version of CentOS with the following command
[root@host ~] cat /etc/*release CentOS Linux release 7.7.1908 (Core)
First, we will ensure that all of our existing software is up-to-date by running the following command.
root@host [~]# yum update
Next, we will change directories in our /tmp folder and then download the RPM file to that directory using the wget command.
root@host [~]# cd /tmp [root@host tmp]# wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.rpm --2020-02-25 07:49:37-- https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.rpm Resolving releases.hashicorp.com (releases.hashicorp.com)... 184.108.40.206, 2a04:4e42:3b::439 Connecting to releases.hashicorp.com (releases.hashicorp.com)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 42576773 (41M) [application/x-redhat-package-manager] Saving to: 'vagrant_2.2.7_x86_64.rpm' 100%[=====================================================================>] 42,576,773 23.8MB/s in 1.7s 2020-02-25 07:49:39 (23.8 MB/s) - 'vagrant_2.2.7_x86_64.rpm' saved [42576773/42576773]
To ensure the file has not been tampered with, we will obtain the checksum for the file and verify it against the HashiCorp’s public key.
(This method is based on the Vagrant defined security policy)
[root@host tmp] wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_SHA256SUMS.sig --2020-02-25 07:53:21-- https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_SHA256SUMS.sig Resolving releases.hashicorp.com (releases.hashicorp.com)... 18.104.22.168, 2a04:4e42:3b::439 Connecting to releases.hashicorp.com (releases.hashicorp.com)|22.214.171.124|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 310 [application/octet-stream] Saving to: 'vagrant_2.2.7_SHA256SUMS.sig' 100%[===============================================================>] 310 --.-K/s in 0s 2020-02-25 07:53:21 (53.7 MB/s) - 'vagrant_2.2.7_SHA256SUMS.sig' saved [310/310]
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_SHA256SUMS --2020-02-25 07:54:02-- https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_SHA256SUMS Resolving releases.hashicorp.com (releases.hashicorp.com)... 126.96.36.199, 2a04:4e42:2f::439 Connecting to releases.hashicorp.com (releases.hashicorp.com)|188.8.131.52|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 727 [text/plain] Saving to: 'vagrant_2.2.7_SHA256SUMS' 100%[===============================================================>] 727 --.-K/s in 0s 2020-02-25 07:54:03 (173 MB/s) - 'vagrant_2.2.7_SHA256SUMS' saved [727/727]
Next, we will create a file called hashicorp.asc and insert the following information into the file using the echo command.
[root@host tmp]# echo ‘-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1 mQENBFMORM0BCADBRyKO1MhCirazOSVwcfTr1xUxjPvfxD3hjUwHtjsOy/bT6p9f W2mRPfwnq2JB5As+paL3UGDsSRDnK9KAxQb0NNF4+eVhr/EJ18s3wwXXDMjpIifq fIm2WyH3G+aRLTLPIpscUNKDyxFOUbsmgXAmJ46Re1fn8uKxKRHbfa39aeuEYWFA 3drdL1WoUngvED7f+RnKBK2G6ZEpO+LDovQk19xGjiMTtPJrjMjZJ3QXqPvx5wca KSZLr4lMTuoTI/ZXyZy5bD4tShiZz6KcyX27cD70q2iRcEZ0poLKHyEIDAi3TM5k SwbbWBFd5RNPOR0qzrb/0p9ksKK48IIfH2FvABEBAAG0K0hhc2hpQ29ycCBTZWN1 cml0eSA8c2VjdXJpdHlAaGFzaGljb3JwLmNvbT6JATgEEwECACIFAlMORM0CGwMG CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEFGFLYc0j/xMyWIIAIPhcVqiQ59n Jc07gjUX0SWBJAxEG1lKxfzS4Xp+57h2xxTpdotGQ1fZwsihaIqow337YHQI3q0i SqV534Ms+j/tU7X8sq11xFJIeEVG8PASRCwmryUwghFKPlHETQ8jJ+Y8+1asRydi psP3B/5Mjhqv/uOK+Vy3zAyIpyDOMtIpOVfjSpCplVRdtSTFWBu9Em7j5I2HMn1w sJZnJgXKpybpibGiiTtmnFLOwibmprSu04rsnP4ncdC2XRD4wIjoyA+4PKgX3sCO klEzKryWYBmLkJOMDdo52LttP3279s7XrkLEE7ia0fXa2c12EQ0f0DQ1tGUvyVEW WmJVccm5bq25AQ0EUw5EzQEIANaPUY04/g7AmYkOMjaCZ6iTp9hB5Rsj/4ee/ln9 wArzRO9+3eejLWh53FoN1rO+su7tiXJA5YAzVy6tuolrqjM8DBztPxdLBbEi4V+j 2tK0dATdBQBHEh3OJApO2UBtcjaZBT31zrG9K55D+CrcgIVEHAKY8Cb4kLBkb5wM skn+DrASKU0BNIV1qRsxfiUdQHZfSqtp004nrql1lbFMLFEuiY8FZrkkQ9qduixo mTT6f34/oiY+Jam3zCK7RDN/OjuWheIPGj/Qbx9JuNiwgX6yRj7OE1tjUx6d8g9y 0H1fmLJbb3WZZbuuGFnK6qrE3bGeY8+AWaJAZ37wpWh1p0cAEQEAAYkBHwQYAQIA CQUCUw5EzQIbDAAKCRBRhS2HNI/8TJntCAClU7TOO/X053eKF1jqNW4A1qpxctVc z8eTcY8Om5O4f6a/rfxfNFKn9Qyja/OG1xWNobETy7MiMXYjaa8uUx5iFy6kMVaP 0BXJ59NLZjMARGw6lVTYDTIvzqqqwLxgliSDfSnqUhubGwvykANPO+93BBx89MRG unNoYGXtPlhNFrAsB1VR8+EyKLv2HQtGCPSFBhrjuzH3gxGibNDDdFQLxxuJWepJ EK1UbTS4ms0NgZ2Uknqn1WRU1Ki7rE4sTy68iZtWpKQXZEJa0IGnuI2sSINGcXCJ oEIgXTMyCILo34Fa/C6VCm2WBgz9zZO8/rHIiQm1J5zqz0DrDwKBUM9C =LYpS -----END PGP PUBLIC KEY BLOCK-----’ >> hashicorp.asc
Now, we can import our key.
[root@host tmp]# gpg --import hashicorp.asc gpg: key 348FFC4C: public key "HashiCorp Security <email@example.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)
Next, we can validate the signature using the following command.
[root@host tmp]# gpg --verify vagrant_2.2.7_SHA256SUMS.sig vagrant_2.2.7_SHA256SUMS gpg: Signature made Tue 28 Jan 2020 04:09:52 PM EST using RSA key ID 348FFC4C gpg: Good signature from "HashiCorp Security <firstname.lastname@example.org>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 91A6 E7F8 5D05 C656 30BE F189 5185 2D87 348F FC4C
After this, we should validate the download.
[root@host tmp]# rpm --checksig vagrant_2.2.7_x86_64.rpm vagrant_2.2.7_x86_64.rpm: sha1 md5 OK
Now we can install Vagrant.
[root@host tmp]yum install vagrant_2.2.7_x86_64.rpm Loaded plugins: fastestmirror, priorities, universal-hooks Examining vagrant_2.2.7_x86_64.rpm: 1:vagrant-2.2.7-1.x86_64 Marking vagrant_2.2.7_x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package vagrant.x86_64 1:2.2.7-1 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================== Package Arch Version Repository Size ===================================================================================Installing: Vagrant x86_64 1:2.2.7-1 /vagrant_2.2.7_x86_64 118 M Transaction Summary ===================================================================================Install 1 Package Total size: 118 M Installed size: 118 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:vagrant-2.2.7-1.x86_64 1/1 Verifying : 1:vagrant-2.2.7-1.x86_64 1/1 Installed: vagrant.x86_64 1:2.2.7-1 Complete!
To confirm that Vagrant has been installed correctly, we can check the version using the following command.
[root@host tmp] vagrant --version Vagrant 2.2.7
Installing VirtualBox on CentOS 7
To employ Vagrant we need to install VirtualBox on our Linux server as well. We can accomplish this by following the steps noted below.
Download the VirtualBox RPM using the following command.
[root@host tmp] wget https://download.virtualbox.org/virtualbox/6.1.4/VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm --2020-02-25 08:26:49-- https://download.virtualbox.org/virtualbox/6.1.4/VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm Resolving download.virtualbox.org (download.virtualbox.org)... 184.108.40.206 Connecting to download.virtualbox.org (download.virtualbox.org)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 106299620 (101M) [application/x-redhat-package-manager] Saving to: 'VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm' 100%[==============================================================>] 106,299,620 16.3MB/s in 8.0s 2020-02-25 08:26:58 (12.7 MB/s) - 'VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm' saved [106299620/106299620]
Download and import Oracle’s public key:
[root@host tmp] wget https://www.virtualbox.org/download/oracle_vbox.asc --2020-02-25 08:27:50-- https://www.virtualbox.org/download/oracle_vbox.asc Resolving www.virtualbox.org (www.virtualbox.org)... 18.104.22.168 Connecting to www.virtualbox.org (www.virtualbox.org)|22.214.171.124|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1734 (1.7K) [text/plain] Saving to: 'oracle_vbox.asc' 100%[==============================================================>] 1,734 --.-K/s in 0.05s 2020-02-25 08:27:50 (34.9 KB/s) - 'oracle_vbox.asc' saved [1734/1734] # rpm --import oracle_vbox.asc [root@host tmp]# # rpm --checksig VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK
Install the VirtualBox using the following command.
[root@host tmp] yum localinstall VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm Loaded plugins: fastestmirror, priorities, universal-hooks Examining VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm: VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 Marking VirtualBox-6.1-6.1.4_136177_el7-1.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package VirtualBox-6.1.x86_64 0:6.1.4_136177_el7-1 will be installed --> Processing Dependency: libSDL-1.2.so.0()(64bit) for package: VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 Loading mirror speeds from cached hostfile * EA4: 126.96.36.199 * cpanel-addons-production-feed: 188.8.131.52 * cpanel-plugins: 184.108.40.206 * epel: mirrors.liquidweb.com 170 packages excluded due to repository priority protections --> Processing Dependency: libopus.so.0()(64bit) for package: VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 --> Running transaction check ---> Package SDL.x86_64 0:1.2.15-15.el7_7 will be installed ---> Package opus.x86_64 0:1.0.2-6.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================== Package Arch Version Repository Size =====================================================================Installing: VirtualBox-6.1 x86_64 6.1.4_136177_el7-1 /VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 221 M Installing for dependencies: SDL x86_64 1.2.15-15.el7_7 system-updates-released 205 k opus x86_64 1.0.2-6.el7 system-base 630 k Transaction Summary =====================================================================Install 1 Package (+2 Dependent packages) Total size: 222 M Total download size: 835 k Installed size: 223 M Is this ok [y/d/N]: y Downloading packages: (1/2): opus-1.0.2-6.el7.x86_64.rpm | 630 kB 00:00:00 (2/2): SDL-1.2.15-15.el7_7.x86_64.rpm | 205 kB 00:00:00 ---------------------------------------------------------------------Total 4.5 MB/s | 835 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : SDL-1.2.15-15.el7_7.x86_64 1/3 Installing : opus-1.0.2-6.el7.x86_64 2/3 Installing : VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 3/3 Creating group 'vboxusers'. VM users must be member of that group! This system is currently not set up to build kernel modules. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64 This system is currently not set up to build kernel modules. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64 There were problems setting up VirtualBox. To re-start the set-up process, run /sbin/vboxconfig as root. If your system is using EFI Secure Boot you may need to sign the kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load them. Please see your Linux system's documentation for more information. Verifying : opus-1.0.2-6.el7.x86_64 1/3 Verifying : SDL-1.2.15-15.el7_7.x86_64 2/3 Verifying : VirtualBox-6.1-6.1.4_136177_el7-1.x86_64 3/3 Installed: VirtualBox-6.1.x86_64 0:6.1.4_136177_el7-1 Dependency Installed: SDL.x86_64 0:1.2.15-15.el7_7 opus.x86_64 0:1.0.2-6.el7 Complete!
If everything went well, we should be able to check the version with the following command.
[root@host tmp]# VBoxManage --version 6.1.4
If it returns the version we should be good to go.
Installing Vagrant on MacOS is pretty straightforward, so we will keep it simple with just the needed steps.
Vagrant installation on MacOS
- Visit the Vagrant download page and click on the MacOS 64-bit link to download the .dmg file to your workstation.
- Once downloaded, click on the file and then double-click the vagrant.pkg icon.
- Review the installer steps and click Install to start setting up Vagrant.
VirtualBox installation on MacOS
As in the previous Installations, we need to install the latest VirtualBox from the following link.
- Download the VirtualBox .dmg file from the link above.
- Double-click on VirtualBox.pkg icon and follow along with the installer.
- Click Install and wait for the installation to finish.
- Restart your workstation.
Now that we have explored what Vagrant is, how to install it, as well as how it can speed up our development process without any hassle and fear of breaking our production site. In the next segment of our article, we will cover common configuration files as well as the usage of Vagrant.
Usage of Vagrant and Common Configuration Files
In the earlier part of our Vagrant article above, we learned and explored how Vagrant is installed on various OS versions and generally what Vagrant does. In the next section, we will go a bit further in depth about its configuration files, how to deploy virtual machines with Vagrant, and how to add additional VM providers to Vagrant.
Common Commands used by Vagrant
[root@host (Tue Mar 03): /]# vagrant Usage: vagrant [options] <command> [<args>] -v, --version Print the version and exit. -h, --help Print this help. Common commands: box manages boxes: installation, removal, etc. cloud manages everything related to Vagrant Cloud destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment upload upload to machine via communicator validate validates the Vagrantfile version prints current and latest Vagrant version winrm executes commands on a machine via WinRM winrm-config outputs WinRM configuration to connect to the machine For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`.
Now that we can see the overall command structure and what various flags are used for, let’s create a new folder called LiquidWebVagrant by using the following command.
[root@host (Tue Mar 03): / ]# mkdir LiquidWebVagrant
Enter the following command to enter the newly created folder.
[ root@host (Tue Mar 03): / ]# cd LiquidWebVagrant/
Now, we can start the new Vagrant environment using following command.
[root@host (Tue Mar 03): /LiquidWebVagrant ]# vagrant init A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
Now that we have initiated a new Vagrant Environment, let’s take a look at the main Vagrant configuration file called Vagrantfile.
The Vagrantfile is the most important configuration file in terms of what we can define for our development environment to function. The Vagrantfile uses a Ruby type syntax, but knowledge of the Ruby programming language is not necessary to make modifications to the file. The raw file looks like this.
[root@host (Tue Mar 03): /LiquidWebVagrant ]# cat 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://vagrantcloud.com/search. config.vm.box = "base" # 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. # NOTE: This will enable public access to the opened port # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine and only allow access # via 127.0.0.1 to disable public access # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" # 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 "../data", "/vagrant_data" ########## Configuration of various options for VM’s providers ########## # 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. # 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 # apt-get update # apt-get install -y apache2 # SHELL end
Deploying a Simple Vagrant CentOS 7 Server With a Predefined LAMP Stack
Now that we see how a basic Vagrantfile appears, like we can begin deploying our Vagrant virtual machines. In this segment, we will be using a CentOS 7 LAMP stack server, which can be obtained from previous link.
- Visit the link from above to download the vagrant file.
- Create a directory (using the following command) in which the vagrant container will be used.
[ root@host (Tue Mar 03): / ]# mkdir LiquidWebVagrant [ root@host (Tue Mar 03): / ]# cd LiquidWebVagrant [ root@host (Tue Mar 03): /LiquidWebVagrant ]#
Initiate the vagrant file from the link above, using the following command.
[root@host (Tue Mar 03): /LiquidWebVagrant ]# vagrant init Gigasavvy/centos7-LAMP A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
Next, we can start Vagrant using the following command.
[root@host (Tue Mar 03): /LiquidWebVagrant ]# vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'Gigasavvy/centos7-LAMP'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'Gigasavvy/centos7-LAMP' version '0.0.7' is up to date... ==> default: Setting the name of the VM: LiquidWebVagrant_default_1583230821780_30210 ==> default: Fixed port collision for 22 => 2222. Now on port 2201. ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2201 (host) (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2201 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 5.0.14 default: VirtualBox Version: 6.0 ==> default: Mounting shared folders...
If there were no errors seen during the install or after running “vagrant up, we can now ssh to our machine using the following command.
[root@host (Tue Mar 03): /LiquidWebVagrant ]# vagrant ssh Last login: Fri Jun 10 19:39:33 2016 from gateway [email@example.com (Tue Mar 03): ~ ]$
Next, enter as the root user (The password is vagrant).
[firstname.lastname@example.org (Tue Mar 03): ~ ]$ su root Password:
Since this server comes with a pre-compiled LAMP stack, let’s check to see if the preinstalled software is working as expected.
Checking the Version of PHP
[ email@example.com (Tue Mar 03): /home/vagrant ]# php -v PHP 7.0.7 (cli) (built: May 28 2016 07:53:22) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
Checking Apache Status
[ firstname.lastname@example.org (Tue Mar 03): /home/vagrant ]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-03-03 05:20:50 EST; 9min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 909 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─ 909 /usr/sbin/httpd -DFOREGROUND ├─1148 /usr/sbin/httpd -DFOREGROUND ├─1235 /usr/sbin/httpd -DFOREGROUND ├─1236 /usr/sbin/httpd -DFOREGROUND ├─1237 /usr/sbin/httpd -DFOREGROUND ├─1241 /usr/sbin/httpd -DFOREGROUND └─1242 /usr/sbin/httpd -DFOREGROUND Mar 03 05:20:48 localhost.localdomain systemd: Starting The Apache HTTP Server... Mar 03 05:20:50 localhost.localdomain systemd: Started The Apache HTTP Server.
Checking MySQL Status
[ email@example.com (Tue Mar 03): /home/vagrant ]# systemctl status mysql ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Tue 2020-03-03 05:20:50 EST; 10min ago Main PID: 906 (mysqld) Status: "Taking your SQL requests now..." CGroup: /system.slice/mariadb.service └─906 /usr/sbin/mysqld Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140717048424576 [Note] InnoDB: Highest supported file format is Barracuda. Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140717048424576 [Note] InnoDB: 128 rollback segment(s) are active. Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140717048424576 [Note] InnoDB: Waiting for purge to start Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140717048424576 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.29-76.2 started; log sequence number 1617055 Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140717048424576 [Note] Plugin 'FEEDBACK' is disabled. Mar 03 05:20:49 localhost.localdomain mysqld: 2020-03-03 5:20:49 140716315473664 [Note] InnoDB: Dumping buffer pool(s) not yet started Mar 03 05:20:50 localhost.localdomain mysqld: 2020-03-03 5:20:50 140717048424576 [Note] Server socket created on IP: '::'. Mar 03 05:20:50 localhost.localdomain mysqld: 2020-03-03 5:20:50 140717048424576 [Note] /usr/sbin/mysqld: ready for connections. Mar 03 05:20:50 localhost.localdomain mysqld: Version: '10.1.14-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server Mar 03 05:20:50 localhost.localdomain systemd: Started MariaDB database server.
We can see that all of our LAMP stack software is functional, so we can now start developing our web application.
Adding Additional Providers to Vagrant
Vagrant provides default support for Docker, VirtualBox, and Hyper-V. It also can manage different types of virtual machines as well. This is done by using additional providers with Vagrant. In this section we will add docker as provider.
You can also visit this page to get a more defined view on how to use docker in this setting. Type this command to begin.
[firstname.lastname@example.org (Tue Mar 03): /home/vagrant ] vagrant plugin install docker Installing the 'docker' plugin. This can take a few minutes... Fetching: backticks-1.0.2.gem (100%) Fetching: docker-0.4.0.gem (100%) Installed the plugin 'docker (0.4.0)'!
This installs Docker as a plugin and now, we can use docker commands.
[root@host LiquidWebVagrant]# vagrant list-commands | grep docker docker-exec attach to an already-running docker container docker-logs outputs the logs from the Docker container docker-run run a one-off command in the context of a container
Bear in mind that this is just one of the many plugins available for Vagrant. As a reminder, the plugins do not install the full software itself on our system.