Try Vagrant they said…

Posted on Updated on

I’d heard good things, but installation and basic setup is not a one click solution. There are things that have to setup to get it going.

Vagrant is basically a way of controlling virtual machines on your computer, for those boxes that don’t really need or have a gui, which makes it great for web development and more.

So, while it sounds easy and great, you may run in to some dramas in setting it up.

Firstly, there aren’t really many front-end GUIs for setting this up. It’s basically command line driven.

So, go here and click on your version. For me, it was Windows x64 and run the msi file.

https://www.vagrantup.com/downloads.html

You also need to install VirtualBox as well.

https://www.virtualbox.org/wiki/Downloads

You will also need to install git

https://git-scm.com/download/win

Secondly, if you are trying to install it on a Windows 7 computer, like I was, your first hurdle will be having the correct version of Powershell. Mine came with version 2, so, I needed to find version 3 – as a minimum.

You find it here: https://www.microsoft.com/en-us/download/details.aspx?id=34595

There’s 4 files to download (plus a readme). You’ll need either the x86, or the x64 files. Only one of them installed for me, because my system said that I didn’t need or was applicable for my computer.

After a restart, and checking I had the correct version by running in powershell:

 Get-Host | Select-Object Version

It told me I had version 3.0

So, good to go?

I started with these instructions: https://dev.to/lechatthecat/how-to-use-virtualbox-and-vagrant-for-windows-1dnn

It gave me a basic centos install. You can try this if you like, but there’s a big downside, because you’ll still have to install everything else that goes with it, such as php, mysql, apache/nginx as well. So, follow a little further below, and I’ll show you a setup out of the box.

vagrant -v
Vagrant 2.0.1

cd C:\
mkdir vagrant\centos
cd C:\vagrant\centos 
vagrant init bento/centos-7.3

After about 10 minutes or so, it’ll download everything. eg:

C:\>cd vagrant

C:\vagrant>dir
Volume in drive C is WINDOWS
Volume Serial Number is 4XXX-XXXX

Directory of C:\vagrant

15/10/2018 03:35 PM <DIR> .
15/10/2018 03:35 PM <DIR> ..
15/10/2018 03:38 PM <DIR> centos
0 File(s) 0 bytes
3 Dir(s) 347,443,544,064 bytes free

C:\vagrant>cd centos

C:\vagrant\centos>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bento/centos-7.3' could not be found. Attempting to find and i
nstall...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'bento/centos-7.3'
default: URL: https://vagrantcloud.com/bento/centos-7.3
==> default: Adding box 'bento/centos-7.3' (v201708.22.0) for provider: virtualb
ox
default: Downloading: https://vagrantcloud.com/bento/boxes/centos-7.3/versio
ns/201708.22.0/providers/virtualbox.box
default: Progress: 43% (Rate: 614k/s, Estimated time remaining: 0:05:35)

In case you didn’t know, there are many different vagrant ‘boxes’ available to download and use. https://app.vagrantup.com/boxes/search

I am just using the bento/centos-7.3 box because the tutorial was easy to follow.

For ease of development, I went with a scotch/box because it contained a full LAMP setup.

cd C:\
mkdir vagrant\scotch

cd C:\vagrant\scotch

vagrant init scotch/box

vagrant up

While that downloads, go and get putty, and an ftp client and watch the videos on here:
https://scotch.io/courses/getting-started-with-scotch-box-vagrant-for-the-absolute-beginner/downloading-and-installing

Some basic commands:

To start the virtual machine:

vagrant up

To stop the virtual machine:

vagrant halt

To restart the virtual machine:

vagrant reload

 

Or… They easier way, is to do the following:

Do all the install business as mentioned at the top of this post, then, open a command box (cmd)

cd \
mkdir vagrant
git clone https://github.com/scotch-io/scotch-box my-project
cd my-project
vagrant up

Then, open up the ip address of http://192.168.33.10/ in your web browser.
The best thing though is that you can then drop and edit your files directly in to

c:\vagrant\my-project

without having to upload, ssh or ftp anything to anywhere…

Just edit away…

For MySQL operations: https://box.scotch.io/docs/

Since using the scotch-box option, it’s been a brease to use, if you are content with a little bit of command line stuff.

There was only one problem I ran in to.

After working on a web app for many years, of which has been functioning well in various production and dev environments with no changes to the mysql config, I came across a problem yesterday where I couldn’t perform a query because I had the “Group By” statement in the query. See here for more details.

I solved the problem by editing /etc/mysql/mysql.conf.d/mysqld.cnf

I added the following line to the bottom of the config file.

[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s