Difference between revisions of "Vagrant"

From rbachwiki
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Setting Up Vagrant==
==Setting Up Vagrant==
[https://www.vagrantup.com Download Vagrant]
[https://www.vagrantup.com Download Vagrant] <br>
[https://app.vagrantup.com/boxes/ Vagrant Boxes]
Make Directory to work in (mac windows or linux)
Make Directory to work in (mac windows or linux)
  mkdir mydir
  mkdir mydir
Line 6: Line 7:
  code . # this open Visual Studio Code with a blank page
  code . # this open Visual Studio Code with a blank page
Vagrant and project files will go into this directory
Vagrant and project files will go into this directory
''' Steps in vagrant setup'''
* config.vm.box - Operating System
* config.vm.provider - virtualbox
* config.vm.network - How your host sees your box
* config.vm.synced_folder - How you access files from your computer
* confif.vm.provision - What we want to setup
<br>
# Download vagrant box from the [https://app.vagrantup.com/boxes/ Vagrant Boxes] Website
vagrant init ubuntu/trusty64
vagrant up # this starts vagrant Should show in Virtual box
'''Vagrant Commands'''
# vagrant destroy - Will completely delete the box and any installed programs
# vagrant suspend will suspend the box
# vagrant resume  - resume from suspend
== Update Features of the Vagrant Box ==
[[vagrantfile|Vagrant Config File]]
vagrant reload # will reload box after config is changed
'''SSH into box '''
vagrant ssh
'''If you want to setup vagrant with a few programs installed, see below. '''
  # -- Provision Settings
  config.vm.provision "shell", inline: <<-SHELL
    apt-get update
    apt-get install -y apache2
  SHELL
'''Instead of including it in the setup file you can include a separate init file'''
config.vm.provision "shell", path: "bootstrap.sh"
above goes in the vagrant file
'''you have to create the bootstrap.sh file and add features'''
'''This particular file sets up a LAMP STACK'''
[[configfile bootstrap.sh config file]]
''' Setup a mysql database '''
mysql -u root -p
$password 123
create database test;
use test;
create table posts(id INT AUTO_INCREMENT, Name VARCHAR(50) NOT NULL, primary key (id));
insert into posts(Name) values('john');
[[phpfile]]
[[Virtualization]] - [[Vagrant]]

Latest revision as of 20:39, 15 February 2019

Setting Up Vagrant

Download Vagrant
Vagrant Boxes Make Directory to work in (mac windows or linux)

mkdir mydir
cd mydir
code . # this open Visual Studio Code with a blank page

Vagrant and project files will go into this directory Steps in vagrant setup

  • config.vm.box - Operating System
  • config.vm.provider - virtualbox
  • config.vm.network - How your host sees your box
  • config.vm.synced_folder - How you access files from your computer
  • confif.vm.provision - What we want to setup


  1. Download vagrant box from the Vagrant Boxes Website
vagrant init ubuntu/trusty64
vagrant up # this starts vagrant Should show in Virtual box

Vagrant Commands

  1. vagrant destroy - Will completely delete the box and any installed programs
  2. vagrant suspend will suspend the box
  3. vagrant resume - resume from suspend

Update Features of the Vagrant Box

Vagrant Config File

vagrant reload # will reload box after config is changed

SSH into box

vagrant ssh

If you want to setup vagrant with a few programs installed, see below.

 # -- Provision Settings
 config.vm.provision "shell", inline: <<-SHELL
   apt-get update
   apt-get install -y apache2
 SHELL

Instead of including it in the setup file you can include a separate init file

config.vm.provision "shell", path: "bootstrap.sh"

above goes in the vagrant file you have to create the bootstrap.sh file and add features This particular file sets up a LAMP STACK

configfile bootstrap.sh config file

Setup a mysql database

mysql -u root -p
$password 123
create database test;
use test;
create table posts(id INT AUTO_INCREMENT, Name VARCHAR(50) NOT NULL, primary key (id));
insert into posts(Name) values('john');
phpfile

Virtualization - Vagrant