I wasn't sure where I should post this so I thought I'd post it here.

Does anyone run linux and have a recommended way to create virtual machines on their workstation? The reason why I ask is that I want to experiment with other versions of PHP without affecting the version of PHP installed on my workstation. More specifically, I want to compile PHP from source and install on the virtual machine so that my workstation's installation of PHP remains untouched. Given that these other versions of php that I'll be compiling might be unstable, I would not want to destabilize my workstation. I hope I might keep the wonkiness contained within the virtual machine.

Ideally I'd be able to create a variety of virtual machines:
start them up
install other php on them
edit my source using the IDE installed on my primary workstation
compile and install my altered source code on the virtual machine with a minimum of fuss
* shut down the virtual machine such that I can fire it up again later and it will retain its state.

I have no idea if any of this is feasible. Input would be most welcome.

    What you have described sounds feasible: you should be able to have a shared folder or something between your host OS and the virtual machine.

    That said, it would be easier if there was a PHP equivalent of Python's virtualenv and Ruby's rbenv.

      I often use Vagrant VMs, and you can configure them to link, say /var/www to c:\your\projects or whatever. (The Laravel community generally uses "Homestead" Vagrant VMs, which gets you set up with the necessary PHP version and such along with all the Laravel stuff.)

      Therefore, my editor is running on Windows and editing files in c:\your\projects\whatever..., and then I can immediately test saved changes in the VM.

        I haven't used Vagrant but I hear it's extremely popular. I generally have a number of different VMs created through VirtualBox. Sometimes you don't even have to create more than one since it allows you to take snapshots. For instance you could run a snapshot with PHP7 RC4 and another snapshot with RC3, but they'd both be on the same VM. Then you could branch off those as well, and I believe you can spinoff an entire VM from a snapshot, too. Most of these features used to be exclusive to VMware, but VirtualBox has caught up to them in the last couple years (and it's open-source and free).

          I use Oracle's VirtualBox, which is free, more/less. I typically run FreeBSD on it, in accordance with my known flaming zeal, but I also currently have one successfully running CentOS.

          Now, granted, I run it on Windows, which is what the company wants me to use. But I've run VBox on other systems in the past (if it'll run on FreeBSD, it will run on Linux, almost always --- typically as Linux is a bigger target the FreeBSD version is a port from it ... ).

          If you want to run multiple VM's at one time, you'll need some hoss hardware: however multi-core CPUs and multiple GB of RAM are pretty common these days. I'm not quite sure that VBox plays nice with multi-core CPUs under my 64-bit Win7 installation, so I all my VMs here are single-core (think about 5-10 year old hardware; that's what I typically set up for resources for my VMs). I have about 6G RAM, so I typically run 1 or 2 GB RAM on my VMs. I manage it all with the Oracle VM VirtualBox Manager, although in some circumstances we run the CLI programs to start VMs at Windows startup. This would be possible in the Nixen fairly easily via cron's @ (or your Linuxen may have other ways you'd prefer).

            dalecosp;11051481 wrote:

            I'm not quite sure that VBox plays nice with multi-core CPUs under my 64-bit Win7 installation, so I all my VMs here are single-core (think about 5-10 year old hardware; that's what I typically set up for resources for my VMs).

            They do. You can specify how many cores a VM will use under Settings > System and then under the Processor tab. I have run two VMs simulataneously with my quad core system (2 for me, 1 each for the VMs) as well as 2 and 2 with a single VM. I am also running Windows 7 x64.

              So I spent nearly two full days upgrading my workstation to Ubuntu 14.04.3 LTS and I see that Ubuntu has package installers for various virtualbox bits:

              $ apt-cache search virtualbox | grep "^virtualbox"
              virtualbox - x86 virtualization solution - base binaries
              virtualbox-dbg - x86 virtualization solution - debugging symbols
              virtualbox-dkms - x86 virtualization solution - kernel module sources for dkms
              virtualbox-guest-additions-iso - guest additions iso image for VirtualBox
              virtualbox-guest-dkms - x86 virtualization solution - guest addition module source for dkms
              virtualbox-guest-source - x86 virtualization solution - guest addition module source
              virtualbox-guest-utils - x86 virtualization solution - non-X11 guest utilities
              virtualbox-guest-x11 - x86 virtualization solution - X11 guest utilities
              virtualbox-qt - x86 virtualization solution - Qt based user interface
              virtualbox-source - x86 virtualization solution - kernel module source

              One can also install vagrant:

              $ apt-cache search vagrant
              vagrant - Tool for building and distributing virtualized development environments

              I also found this post Why should I use Vagrant instead of just VirtualBox?. Looks like Vagrant runs on top of virtual box and has a significant value-add.

              On the other hand, I'm a bit suspicious or running virtual machines created by someone else. This seems to be one of the chief benefits of Vagrant. Where do these OS images come from? It seems a little suspect to me that I could install virtualbox and suddenly be able to fire up Windows virtual machines without paying license fees to M$. I also wonder how much these virtual machines are sandboxed or whatever. Are they chrooted or something? Jailed? Or can they right my whole file system?

                VirtualBox doesn't create virtual machines for you or provide you with OS images. That's all up to you. VirtualBox is just, for lack of better explanation, virtualization software. You still have to create the virtual machines and provide the OS image yourself. Since Linux is free it's incredibly popular for this sort of situation. Sounds like Vagrant does a lot of the grunt work for you so perhaps it's the best option. Personally I'd stick with VirtualBox but that's just me.

                As for sandboxing the guest OS and the host OS are pretty much separate. It's like having 2 separate PCs sitting next to each other on a table. The level of connectivity depends up to you and your needs. You can control things like shared folders, clipboard, drag & drop, etc. in the settings for each virtual machine.

                  Bonesnap;11051519 wrote:

                  VirtualBox doesn't create virtual machines for you or provide you with OS images. That's all up to you. VirtualBox is just, for lack of better explanation, virtualization software. You still have to create the virtual machines and provide the OS image yourself. Since Linux is free it's incredibly popular for this sort of situation. Sounds like Vagrant does a lot of the grunt work for you so perhaps it's the best option. Personally I'd stick with VirtualBox but that's just me.

                  I've watched a rather long video that shows how to install Ubuntu using VirtualBox, but the guy is using VirtualBox for windows. He fails to mention what some of the software is or what a "virtual guest" is but it looks pretty informative. Very time consuming! I can't help but wonder if you can take a snapshot of a VM once you've got it all set up so that you can "branch" it and save to distinct disk images?

                  Bonesnap;11051519 wrote:

                  As for sandboxing the guest OS and the host OS are pretty much separate. It's like having 2 separate PCs sitting next to each other on a table. The level of connectivity depends up to you and your needs. You can control things like shared folders, clipboard, drag & drop, etc. in the settings for each virtual machine.

                  I'm not so sure how separate they are. They are definitely using the same physical hard disk. Also, as I mentioned in my original post, I want to run Eclipse on my workstation and have the changed files updated on the virtual machines. I haven't seen vagrant in action yet but if I'm going to install some Ubuntu image created by some company or individual I've never heard of, I expect I would want to be sure that virtual machine CANNOT EVER READ MY WORKSTATION'S FILE SYSTEM.

                    sneakyimp;11051521 wrote:

                    I've watched a rather long video that shows how to install Ubuntu using VirtualBox, but the guy is using VirtualBox for windows. He fails to mention what some of the software is or what a "virtual guest" is but it looks pretty informative. Very time consuming! I can't help but wonder if you can take a snapshot of a VM once you've got it all set up so that you can "branch" it and save to distinct disk images?

                    Yes, once you set up your virtual machine, go to the VirtualBox main window, select the VM you have just set up, and click export appliance. This export file can be sent to others to set up the same box. If however you just want to start with the same box as another locally, then in the same VirtualBox main window, right click on your virtual machine and go to clone.

                    sneakyimp;11051521 wrote:

                    I'm not so sure how separate they are. They are definitely using the same physical hard disk. Also, as I mentioned in my original post, I want to run Eclipse on my workstation and have the changed files updated on the virtual machines. I haven't seen vagrant in action yet but if I'm going to install some Ubuntu image created by some company or individual I've never heard of, I expect I would want to be sure that virtual machine CANNOT EVER READ MY WORKSTATION'S FILE SYSTEM.

                    The virtual machine is an isolated machine with only access to the virtual disk you create for it. Unless you use Virutalbox's shared folder feature, in which case any folders you choose to share to your machine, will be mounted and accessible within the VM.

                      I usually just open up a terminal or cmd window, go to the directory where I have the vm, and type "vagrant up". It takes care of launching VirtualBox in command line mode. Just a personal preference thing, not saying it's necessarily better that way. (You can do "vagrant suspend" when you want to close it but save the current state, or "vagrant halt" to do a complete shutdown.)

                        sneakyimp;11051521 wrote:

                        I've watched a rather long video that shows how to install Ubuntu using VirtualBox, but the guy is using VirtualBox for windows. He fails to mention what some of the software is or what a "virtual guest" is but it looks pretty informative. Very time consuming! I can't help but wonder if you can take a snapshot of a VM once you've got it all set up so that you can "branch" it and save to distinct disk images?

                        I can sympathize with the lack of explanation regarding terminology; I have run into that issue when learning Linux and all its accompanying fun. Basically the host is your actual computer/OS. You clearly run Linux so your host OS is Linux. A guest OS is simply an OS that runs in a virtual machine, which of course you can have many.

                        It can be time consuming in the beginning but once you get the hang of it it's not so bad. And yeah, as Derokorian confirmed, you can create separate virtual machines from snapshots. Which is nice because you can create a base for which to branch off of.

                        Also, I know you don't use Windows, but one neat thing is if you create a virtual disk in the *.vhd format you can actually boot your physical PC from it, even if you don't have an OS on your PC (Windows 7 Ultimate and Enterprise only, though).

                        sneakyimp;11051521 wrote:

                        I'm not so sure how separate they are. They are definitely using the same physical hard disk. Also, as I mentioned in my original post, I want to run Eclipse on my workstation and have the changed files updated on the virtual machines. I haven't seen vagrant in action yet but if I'm going to install some Ubuntu image created by some company or individual I've never heard of, I expect I would want to be sure that virtual machine CANNOT EVER READ MY WORKSTATION'S FILE SYSTEM.

                        They are very separate since the guest OS operates solely in a file container (which I believe can be encrypted now in version 5+). It has no knowledge of your host's file system and therefore you can't run a command in your guest and have it accidentally delete something on your host**. Virtual machines are very popular because of this isolation which is why they're frequently used for testing alpha/beta software or software that most would consider "sketchy".

                        ** If you share a folder or directory and you run a command in your guest to do something with that folder then yeah, you'll affect your host installation, but that applies to any kind of mapping between any operating systems. I think this is one area where you can ease your concerns. :p

                          Bonesnap;11051533 wrote:

                          ...or software that most would consider "sketchy".

                          Yeah, I use a VM to install programs from untrusted sources before they go on my main os. If it bricks my VM, I just revert to the last snapshot. Speaking of snapshot, this is another awesome feature of VirtualBox, when in the main window you can select a vm, and go to the snapshots tab (top right, it defaults to Details) and take a snapshot of the current state. Then you can try something risky and revert to the snapshot oh so easily.

                            Alrighty thanks a ton for all the info. I think I'm learning toward VirtualBox, but would like to clarify a few things mentioned in this Vagrant vs Virtualbox comparison.

                            It saith:

                            Vagrant is used to set up one or more virtual machines by:
                            Importing pre-made images (called "boxes")
                            Setting VM-specific settings (IP address, hostnames, port forwarding, memory, etc.)
                            * Running provisioning software like Puppet or Chef

                            Note that it doesn't install software or set up the machine past loading the VM and setting VirtualBox settings. Think of it as a scripting engine for VirtualBox.

                            Here are some reasons I've seen for using Vagrant over just VirtualBox.

                            1. Set Up Multi-VM Networks with Ease
                            Most of the Vagrant power-user content I've read has been about setting up multiple VMs at the same time. Vagrant gives you a single config file to set these up, enabling you to launch all of them with one command...

                            2. Source Control
                            By putting the settings in a text file, it enables the configuration to be put under source control. Made some changes last week and accidentally broke the image? Just revert the changes and reload the VM. You can accomplish this with VirtualBox snapshots, but it will take up much more space than just a Vagrantfile.

                            3. Various Platforms
                            There's a large number of boxes available at sites such as http://vagrantbox.es. This enables you to try various OSes or distributions, applying the same provisioning to set up similar environments.

                            I don't need multi-VM networks at this point, I'm suspicious of sites like vagrantbox.es (but I can see how this might be quite powerful -- people sharing boxes sounds like good stuff). I dread tackling not just VBox and Vagrant but also Puppet and/or Chef. The one feature of Vagrant that seems immediately helpful and useful for my situation is that maintaining snapshots sounds like it'll involve really big files. I'm guessing these snapshots will be at least the size of the installed OS files and possibly as big as the entire amount of space allocated to the VM -- e.g., ~10GB or more.

                            Any detail you guys can offer on managing snapshots? For example, I need three VMs, both Ubuntu 14.04.3. One one I want to install PHP 5.5 to test a module. On another, PHP 5.6. On the third, PHP 7. Am I looking at 30GB of files?

                              sneakyimp;11051551 wrote:

                              Any detail you guys can offer on managing snapshots? For example, I need three VMs, both Ubuntu 14.04.3. One one I want to install PHP 5.5 to test a module. On another, PHP 5.6. On the third, PHP 7. Am I looking at 30GB of files?

                              From my experience, snapshots are incremental. For example, the Windows 7 virtual machine I have at work, I created a 25GB virtual disk and I have a total of 8 snaphshots. The snapshots take up a total of 38.8GB for an average of 4.85GB per snapshot. For a Linux installation I imagine they'll be smaller. If I look at the actual snapshot files it appears most of the files are between 2-3GB and there's one really large one (22G😎, which was the first snapshot I made after I had installed all the Windows updates. The subsequent snapshots are all much smaller. Chances are you're looking at snapshots in the 2-3GB range.

                                I just took the first snapshot of my CentOS box running PHP7, it took up 1.5GB. Oh and it took less than a minute to create the snapshot.

                                  a year later

                                  Can anyone help me get clear on the networking options for this virtual machines? I'm reading the CHM documentation on Virtual Networking and would like to know if I understand this correctly.

                                  6.3 Network Address Translation (NAT)
                                  Virtual machines can connect to the internet but not to each other. Virtual machine and host (i.e., my workstation) are on entirely different networks (i.e., 192.168.1.x for my workstation versus 10.0.x.x for virtual machines) so host cannot "see" virtual machines via network -- no SSH, no HTTP, etc., between host and virtual machines.

                                  6.4 6.4. Network Address Translation Service
                                  Not clear to me how this relates to 6.3, but apparently you can group VMs into named networks so they can interact with each other? Can host contact VMs for ssh, http, etc?

                                  6.5. Bridged networking
                                  Device drive on host is somehow used to route both VM (guest) and host traffic. VMs can communicate with 'outside world.' VMs appear as connected on the network? Host can talk to VMs? How are IP addresses allocated and determined?

                                  6.6. Internal networking
                                  Similar to 6.5, but VMs can only communicate with each other? Traffic is not routed via the host machine's NIC and so it cannot be snooped by Wireshark et. al.

                                  6.7. Host-only networking
                                  Very similar to 6.6 except that a quasi-local-loopback network interface is created which can be snooped by wireshark.

                                  The help file descriptions in the user manual (found here don't make a lot of sense to me.

                                    In regard to VirtualBox disk space and images, the VDI files can be set up as "dynamically allocated", however, unless the guest OS has the ability to dynamically resize its partitions, you still end up with big files. The VDI for my local FreeBSD Virtualbox machine is right at 100GB; the CentOS one, which has less disk space allocated, is over 25GB. I'm not certain, but I would expect the storage scheme for a "server farm" would typically involve some sort of network-file-system or SAN.

                                    As for networking, I simply run them in "Bridged Networking" mode ... they act as servers we can access from anywhere inside the LAN. The "corporate firewall" and the LAN routing is supposed to ensure that they're not accessible to outside.

                                      dalecosp;11058809 wrote:

                                      In regard to VirtualBox disk space and images, the VDI files can be set up as "dynamically allocated", however, unless the guest OS has the ability to dynamically resize its partitions, you still end up with big files. The VDI for my local FreeBSD Virtualbox machine is right at 100GB; the CentOS one, which has less disk space allocated, is over 25GB. I'm not certain, but I would expect the storage scheme for a "server farm" would typically involve some sort of network-file-system or SAN.

                                      Thanks for this helpful comment. In my case, I do not need to access these VMs except from the workstation on which they run. I opted for dynamically allocated sizing. I don't think this results in any partition manipulations on my machine's drives. So far, there's just one *.vdi file that's about 2.3GB -- this is just Ubuntu 16 with apache & php on it.

                                      dalecosp;11058809 wrote:

                                      As for networking, I simply run them in "Bridged Networking" mode ... they act as servers we can access from anywhere inside the LAN. The "corporate firewall" and the LAN routing is supposed to ensure that they're not accessible to outside.

                                      Thank you for providing a real-world example here. The documentation is pretty prolix but somehow fails to communicate what the different modes mean in any way that I can understand. Reading comprehension has never been my strong suit, but I think the documentation could be a lot clearer--like your post is!