Using Varying Vagrant Vagrants 2

VVV 1 is a popular local developer environment, but VVV 2 is now available with significant improvements to site setup.

This session will walk through the new features, and how to migrate to VVV 2


Slides

Video

Transcription

ALICE STILL: How is everyone going?  Good.

We have got Tom Nowell talking now.  Tom is a VIP … at WordPress.com, community moderator, project lead for the WordPress, the right way e-book.He is also the lead organiser of WordCamp Manchester which is happening when?

TOM J NOWELL: Sometime around October, November we don’t have an exact date at the moment.  Keep your eyes peeled.

ALICE STILL: Tom is going to be talking about using Varying Vagrant Vagrants, talking about the recent features.

TOM J NOWELL: Hello.  Before we get started, hands up who has used VVV in the past?  Okay, who is already tried VVV 2 in the last few days either by accident or?  Okay.

Who here has never used vagrant or any of this at all and is curious and is just looking to  — okay, fair number of people from all sides.

So, this talk will say what it is, what changed from version 1 to 2.  Moving from 1 to 2 and then setting up a site, moving sites from VVV 1 so they work in VVV 2.

VVV is a local developer environment, lets you instead of using a server somewhere far, far away, use the machine in front of you.  Why you want that?  So something you might be an obvious question for you some of you.

For example, every now and again I like to write code I might be on a train or I get asked, can you change?  I have just gotten on a train, going through security, not internet for the next 3 or 4 hours, I could have done the work.  If I have a local developer environment that is not a problem.  I can turn my wi-fi off and put staff in aeroplane mode and it still works, no worries about up loading files it is all right in front of me.

So there is a lot of projects that do these things, some of you maybe more familiar with mamp, that do similar things, but are more primitive and have versions.  VVV it is completely free and anyone can use it.

So, it gives you a lot of things out of the box, which is one of the other things which is useful rather than just handing you a web server and letting you loose and letting you set everything up yourself, gives you a life, so you don’t have to go through the process of figuring out to install php and how it should be configured getting the right database in the right version, setting up with users and access, all there for you.  Gives you an object cash, not every host has it.  Sometimes you can write code and not realise the object cash is there.

There is nginx, and site provisioning, which will set up sites for you, so when I run VVV, I turn it on rather than going to my local website,.local or whatever it is, that the people built it have determined I might have my own site and it might have my own domain in it.  It will put it in the host file.  It will do a lot of other things I am not aware I need.  When it comes to that points it is there.

At the same time it is a standardised system, if you are working on a server, if you are working with mamf or other environments that doesn’t use virtualisation, something might work on your machine, but might work differently on your machine, trying to figure out what is going on, when you don’t have a standardised set up is different.  With vagrant based systems when you turn it on, you end up with exactly the same system it is always, something that you can expect and rely on in the sense that my VVV will be the same as yours as yours as yours and so on and so forth.  I don’t need to worry about whether you installed something last year or whether there is something interfering or something causing problems.  Simplifies a lot.

You will need SSH client, install git for that, if you want to install windows.  You will want vagrant and then you will need virtualbox that host it is environment, install the 3 things, make sure they are the latest version at the moment.  Sometimes people have out of date versions, best to keep up to date.  Then down load a copy of VVV, you can do this several ways, do a git clone, you can click the down load zip button and it will package it up.  Put it somewhere on your computer, I would recommend somewhere in the home folder so it is easy to get to.

Then run the commands, vagrant plugin install, … host updater is a plugin that does the host file modification, so you are not editing protected files and adding IP addresses that happens behind the scenes.  Trig.  …

Then finally vagrant up-provision, when you do this, this is the beginning where you have a brand new virtual machine and it needs to fill it with stuff, it is going go away and down load the software, install php and configure it and put everything together and figure out where word press will go.  You will see lots of stuff go past on the screen.  Just go away and come back and as long as the message at the very end is not a red line saying something went wrong, then you are set.

At that point you go the VVV.dev in your browser and you can have a nice screen or run vagrant status and you should see something like this, every time you run a VVV, you will get the nice logo as well as documentation, that might be expanded in the future, but you will also see current machine states powered off, so there is a bit of terminology.  When we, when we talk about things like … and stuff, they have an interview with a little button, turn it on or off.  Maybe a few status lights to say is the database working or not.

Vagrant up, to turn the machine up or off to stop it.  There is two other commands I will mention later, these are the ones you will use the most if you are not comfortable with the terminal.  You have the benefit that you only need to remember these two commands and but, if that is too much for you and you are not comfortable with that, there is a piece of software called vagrant manager.  That will put a little entry in your system trail or your menu bar which will let you actually click vagrant stop and vagrant up and it will tell you there and then in the graphical user interface, that I have never had much use with that.  You may prefer that.

So what changed in VVV 2?  So the big change is this file.  So VVV 1 you had a www folder, inside that, a load of sub folder with websites, it would go through and do a great big search of all the folders and files and trying to find a possible thing that could possibly be a VVV site, so it can turn it on.

That worked for a lot of people, it has some advantages that for example, I had a project where I took about 40 different websites and the piece of work was to measurement one big site.  But then I would be asked, we need the small change on let’s say (INAUDIBLE) then I would go in there and turn it on, before that, it has to go through all 42 other sites then the one that got merged.  At which point I have been waiting for about 40 minutes as it has been setting up hundreds of different sites and running all the scripts.  If you wanted to get around that, you had to go into file explorer, move the folder out of VVV and wait for it to copy the hundreds of mega bites of files it was a nightmare.

But, this config file represents a list of your websites as VVV sees it, which allows you to specify a lot of options.  So this is the default minus one or two comments.  It shows you exactly what you get out of the box with VVV.

So you get a copy of WordPress, standard, latest version of WordPress, no bells or whistles, standard install local.wordPress.dev, and a WordPress develop install.  You can see the different url’s, you can add more, change them around.  This file is for you to edit.  If you don’t want the installs just delete them.  That is all you need to do.  Remove those lines and it is done.  If you want to add another one, add another one.  You can see here there is a section example site and a few other examples in the main file you can use if you down load VVV you will be able to see and see further examples and further slides in a moment.

Also down here, there is a utilities section, you can see here for example, if you don’t want phpmyadmin, remove it or copy it out.  If you want to remove it or add it back in, for whatever reason you can do that as well.

You get a hand full of tools which is really useful.  But one thing that is important is that if you are using git and you make changes to this and pull it down, and maybe I or someone else made improvements to the file, you will maybe have a few conflicts but they are easily side stepped.  So copy the files of VVV-custom.yml, that is no longer an issue, I know some people use a command line tool called VV.  I have disagreements over that kind of approach.  That will automatically copy the file now as well.  It is an easy step, you can copy it over into the file explorer.

So, a lot of people have VVV 1 sites and they will have been going through and thinking, I will pull down the latest changes and then surprise surprise surprise, they see the VVV 2 logo, first thing, back up the database.  One of the things that the triggers did for you, every time you turn off a vagrant machine, backs up the data and puts it in a folder for you, does it any time you run vagrant halt or destroy, does other things as well.

But once you have done that, you want to throw away the box, this destroys the copy of VVV, you still have all the files there and the database, then run another vagrant up position, that capital V is there because Google docs tried to be helpful but this will do the initial fresh build again, down load the operating system and nginx database and figure that out again, do it in a fresh clean copy that has everything that VVV 2 needs.  If you don’t do these things, all the things from the previous versions come along, some people with VVV 1 has a subsystem on there, that has been removed from 2 years ago but it is still there for backwards compatibility.  At the this point, make a cup of tea or coffee, or whatever your thing is.

Yes, at that point you want to move over your VVV 1 sites.

But one thing to note is that if I go back here, and it backs up your database, there is something that it does if when you start vagrant up and it sees that there is a database but it is empty, it will automatically restore from the back ups.  So, you may not need to restore your database at all, it might do it for you.

Let’s say I have a VVV 1-site, I have been working on this site for a long time, upgraded to VVV 2, if I don’t do anything, I do my vagrant up position, I will get the dash board, VVV hasn’t been told about this site.  It is not in the config.  So you need to tell it.  We do that by adding an entry under the site.  So, I simply give it the name of the site, VVV 1 site and I tell it what host it uses.  Then vagrant real open provision, every time you change the config file, VVV needs to know about that, you need to reprovision, at any point you are unsure of whether it is something that is taken effect, run this command and it will run the provisioner automatically.

So at this point now it knows that my site is there and it will load it.  But, maybe I want a brand new site.  So, again, you add it to VVV custom y ml, I have called it a new site.  I specified a git repository there, this automatically creates a WordPress and allows you the have multioptions, it saves a lot in the past with VVV 1 you had to write a provisioning script that creates the database and installs WordPress.  We have done that for you now, that can be a fork of that repository or something of your own creation, it could be an existing VVV 1 site as long as it is mentioned in this file and VVV knows about it.  It will go off and do what it needs to do.  In this case, this is all I need to do the make the change.

When I provision VVV will see, we have a new site, never seen it before.  There is no folder for this.  Let’s do a git clone, let’s check it, let’s pull it down, we know what the site is called, put it in the host file, once this command is done, the user will go to new site.com and there it is, a brand new WordPress theme and default user and they can log in and make whatever changes they want.  I can do this many times.  This is an example of what it looks like in a full config file, you can see I have list of files there.  I have inserted it there and I can add another one here and keep going and going and add as many sites as I want.

Or remove them or change their names or whatever, it is entirely up to you.  Again always vagrant reload provision whenever you make a change, as I say you might want to change changes and realise you have not run the command, and VVV doesn’t know what you are on about but maybe you have an existing site?  My recommendation would be to do something very similar to use what you have just seen again and then use that as a starting point and then fill that particular site with the content and the themes that you want.  Once it is done the vagrant reload provision, you can add in themes, using the themes or just on the files system you are just moving folders over and copying and pasting it is up to you, you might want to import using (INAUDIBLE) or my sql, you have those options, first reposition, copy of files and database over and at that point it is a standard migration as if it was from one server to another or but, instead of a server it is your own local machine.  It has done a lot of the steps for you, if you really wanted to, you remove the repo line and it will create the folder, but you need to fill it with stuff.  I will get into that later but this, this is a good example of setting up site scaffolding and WordPress install.  Again, always vagrant reload dash dash provision.

So, I will talk through a handful of more advanced items, things that maybe new to you if you have only worked with VVV 1 and things that might not have known full stop.

So, where I was talking earlier about git repo, there is a folder and has files in it.  VVV, … sets up the site.  This is what tells it how to install WordPress and all the other steps, so for example, I have a developer environment that has a custom repo, in that installs WordPress and then a load of plugins, it has a check, if WordPress is installed, instead of installing them update them and do a few check outs as well.  I can put anything I want in there, I mean technically it doesn’t have to install WordPress, it could install a static html or even something like Drupal or Droomers – I don’t know why you want to do that. There is VVV-nginx {inaudible} 95 per cent of people.  This file shouldn’t be changed; there is no reason for them to go in there and change things. And, so, for a lot of people it would be a copy paste but right now because of that repo you don’t need to bother with that; and if you are ever trying to do anything that wasn’t related to PHP you might want to change that or you might have other options you needed but that option is there.

VVV 2 prefs, they’re in a provision subfolder but backward capacity, so VVV 1 site still works, you can keep them in the root folder. There was also VVV-hosts file you can still use it but it’s for legacy reasons and that may go away in the future.

You also have per site options, so when I mentioned before add a site to the conflict file and it had the repo option and had the host there are a lot more options than that, so I can do skip provisioning. So, earlier when I was talking about my 42 multi-sites and spending ages and pulling my hair out because it was taking so long moving folders; I don’t need to do that any more.  I just need to skip and provisioning is true.  VVV says I know about this site, now you told me not to bother; I am going to gloss over and go to the next one, so you might have hundreds of sites in your conflict file but you have skip provision and true, so maybe only 4 sites out of 100.  You can save a lot of time.

You may not like the main master branch of your git repo, you may have something else and you have the option with the branch option to change to say develop another one if you choose to.  You might want to have the same site multiple times, but you have one for master, one for feature branch, one for hot fixes, table experimental; it’s entirely up to you.

There is also custom folders.  In VVV 1 everything was in the www folder and it looked in there but now you can put the folder anywhere you want.  You have to define both keys so you can set where it is on your machine and you can also set where varying vagrant vagrants things it is inside the virtual machine, so you might not want forward slash SRV www; you might want forward slash {inaudible} instead, or you may need something set up in a special place so you can set that at the same time.

You can have the actual site itself when you are editing in may be in your mind document folder or pitches or somewhere else or in other uses, this helps a lot when it comes to things like sim linking which aren’t followed. That’s not necessary now. You can have multiple sites running out of the same folder if you really wanted to.

And here is an example of that.  These are absolute paths, so in this case I’ve put it as a subfolder of my documents folder, then I’ve put it in a different place on my server.

So here I might have something different from examples that I could call it moomins or banana or cats; it’s entirely up to you and you have this flexibility and you can do it for multiple sites.  I could have example sites in that folder but then I’ve my test site in another folder; I could have them in the same folder. This is something that is quite useful.

And here is an example where I have done it in a full config example so you can see the context.

You can also have custom PHP versions and not only that this isn’t – here I’m not telling VVV to use PHP 5.6, I am telling a specific site to use 5.6.  At the box it will use PHP 7 but you can also say I’m going to have the same site 3 times, I’m going to have the site this is running 7.1 and then again running 7 and then again running 5.6.

So you see here I have changed my example sites are on PHP 5.6 but I’ve also set WordPress default to use PHP 7 so that I can compare and contrast.  The only thing to note is if you do add another PHP version you will want to add this section here.  So VVV knows to install that version of PHP and make it available for any of the sites you have.

There is also – if anyone has been to a contributor day and tried to set VVV up or any other vagrant or any other local environment, sometimes you can run into problems and a lot of these problems are pretty common in terms of they’re not a wide distribution.  So here for example if VVV decides we need an IP address that the local machine can contact us, need to know where you’re going when you’re in the browser so we picked this one but someone else on the network for some other reason has exactly the same one they’re going to clash.  It’s easily fixable.  There is the documentation that goes with that but it can take a while to figure out exactly what the problem is if it happens. It’s very rare but it does happen.

If you make a typo in VVV custom YML it will tell you and you will have to go in and fix it before you can vagrant up provision or it won’t finish.

If you are doing a vagrant up or vagrant halt and your machine lost power may be there is a power cut or your battery is rubbish, bad things can happen that can ruin your operating system without any VVV stuff.  I’ve had windows XP machines that have been crippled as a result of that, maybe someone forgot to put a thing in the electric meter, but it can happen as well with virtual machines.

If you have out of date versions of vagrant and virtual box sometimes that can cause problems and there is an easy fix for that.  Just up-date them.

If you downgraded from VVV 2 to version 1, not sure why you’d want to but it’s not supported and you shouldn’t do that.  You might end up with all sorts of strange and wonderful problems.  Don’t do it.

At the same time again if it’s all messed up if nobody knows what the problem is and it’s completely lost cause, run vagrant destroy to get rid of VVV and restart from scratch and always have database forward slash backups and database named at SQL, so if you decide you don’t want VVV fullstop you can take these files and take all your backups and stuff and take them elsewhere and this may be useful for other reasons.  You might decide you want to use this and take that SQL file and put it on a production server because you’ve been messing round with your computer and are happy with the results.  Or may be there is a copy of the content on your machine that you are happy with but your colleague wants a copy as well, it might be easier to send them this file and for them to do their own thing importing.  You have that option.  You can do whatever you want with those files.

So, I would recommend that you look at the documentation if you have any problems with the documentation come find me because I wrote most of it.  There is also the main web-site and of course there is Loreli over there who wrote half of it.

I’m Tom Nowell.  I am at Automattic. I work on the dot V team and I deal with big clients who have millions of page views every week, if not billions every month.  I blog at Tomjn.com and you can see me on Twitter at tarendai and if anyone has any questions, thank you?  {Applause}.

I’ll admit that my eyesight is not the best so if you start waving your hand I may not see.

FROM THE FLOOR: Hello, Tom.  With the custom YML file in our case when we create a new instance of our local work flow just our client work we would ideally want to add in, we might store the site settings in the repo that we pull down then want to add that into custom YML file programmatically.  How do you recommend that?  Is there any native author party tools to do that or just append that to the YML file through shell command or something?

TOM J NOWELL: You would need to mention the site in the YML file for VVV to know about it there is some flexibility depending on how good you are with servers and bash scripting but you can do some of this stuff in the VVV-init.  Ideally – you can do some things for example host with VVV-host but ideally you would do all of your provisioning in your VVV-init that’s – and try and use any variables you can from the YML file.  I know there is a handful of things that different provisioners try and do, for example, custom site will try and predict what the database name and what the URL will be if it isn’t there based on the name of the site and I’ve written things that do a lot of stuff like that like trying aside from the name of the site URL of the site, the database name a lot of things like that it will try and figure out.  So I think, I know, it’s somewhat of an open ended question.  There is option you can add your own conflict options to the YML file.  I can go into that if you want after questions and walk you through that.

I’m not sure if that really answered your question?  Okay.  Next question?

FROM THE FLOOR: Hi Tom, can we specify databases like MySQL versus MariaDB?

TOM J NOWELL: You mean if you don’t want to use MariaDB but want to use a different version?  You could but it’s more involved.  If I go back and see along here.  This utility section you can add things there but it’s not something that is well documented and it’s a little more involved and once you add something there you have to add to an extra section of what mentioned there and then mention it by name and it will check it out and there is a provision dot SH that runs but after that you’re entirely left to your own devices on that file so it might {inaudible} wrap or get updated whichever it’s kind of left errors a task for you to do rather than any recommended guidelines it hasn’t much structure.  That’s how you would do that but in terms of replacing MariaDB I’m not sure that’s possible at the moment.  I’m not – sure you could install another database but haven’t it play correctly I don’t think I know enough to really say the steps involved.  Sorry.

Next question?

ALICE: Any other questions?

FROM THE FLOOR: Hi, Tom.  Does VVV 2 play well with other virtual machines?  VM ware or anything like that?

TOM J NOWELL: At the moment virtual box is recommended mainly because it’s free and everywhere but you can use others.  You can use VM ware, you can use some of the – I don’t know very many providers of virtual machines although I know VM ware is one of them and I know one or two people who use them; I would recommend them although the problem there is that virtual box is free and those might not be.  So it very difficult to recommend something that you’d have to shell money out for when it works in virtual box.  So, I don’t know if you have any installed on your machine that you’ve been working with?  But at this point we’re moving outside of the VVV realm into the general vagrant realm and there is a lot of support for a lot of different providers out there some of which are experimental, some of which are quite well-established and virtual box one is the one that’s probably used most.  So I recommend starting with virtual box and if you have problems with virtual box then move somewhere else or if you paid out money already.

FROM THE FLOOR: If you’re using with VVV it’s using nginx but if you are using Apache are there likely to be any compatibility issues moving from one to the other?

TOM J NOWELL: So I think the question there was this uses nginx but if your site uses Apache would there be any issues?  That depends.  I know with Apache you can use modern re-write rules and can put re-write rules in there and some people do that.  My personal recommendation and this isn’t a VVV recommendation, it’s just a general thing, if you are doing re-write rules in WordPress you should use re-write rule APS, not Apache re-write system otherwise you have no way of modifying thing that run time; it might have other consequences you’re not aware of and you’re kind of stuck with Apache, whereas I know some plugins like simple redirects will work on nginx and Apache just because it’s not a server specific thing.  If you do have custom rules for whatever reason and I can’t possibly guess at all of the rules that could possibly be in there you would want to modify vvv-nginx.conf.  I’ve added a rule in one of my own custom repositories there which implements something specifically for WordPress.com testing but for the most part that’s not going to be an issue.  If you have a standard WordPress install the nginx rules that come with VVV will for the most part do you perfectly fine.  You won’t notice.  It never caused a problem for me going for it.  As I say can’t counter every edge case.

Any other questions?  If anybody has any questions or they want to work with something and they don’t feel they can come up and do it in front of everybody and be recorded I’m going to be around the rest of the day and I’m happy to work through things if you want to go in depth on something and try something out.  Come find me.

ALICE: Thank you very much.  {Applause} Thanks, Tom. So it’s lunch time now and back in again at 1.30, so see you all later.

Speaker