Control VirtualBox from a Script

I recently rebuilt my server and reinstalled Ubuntu 18.04 to two drives using RAID. One of the first things I did was to reinstall VirtualBox and phpVirtualBox, in order to spin up virtual servers. This is a very handy way of testing applications or doing work on your server without risking either damaging and corrupting your main server, or polluting the file system with random files and debris if you need to rollback or undo the work you were doing.

There are many good guides online on how to set up virtual box and the PHP interface so you can control it over a web interface. While I can get Virtual Box itself to install and run successfully, I have not had such luck with the web interface.

Googling the error messages and testing various config settings did not work out, and I was getting worried that I would not be able to use Virtual Box. I have found this to be one of the tools I get the most use out of, so this would have been quite a problem.

I realised then that phpVirtualBox is only an interface to the virtualbox commands, and you also have the option of controlling it from the command line. While it would be a challenge to remember and type the lengthy commands each time you need to spin up, shutdown, pause or delete a virtual server, putting them all into a script would be a very practical way of solving the problem.

It is not as pretty as a graphical web interface, but if you want to keep moving on, it does the job!

Click here to download the script.

Use chmod to change user permissions to rwx (read write & execute)

Using the Script

  1. Download and save the script to a file on your server, ideally in your home directory.
  2. Set the permissions to make the file executable.
  3. From within the directory in which the script is saved, run ./

In its current form the script works perfectly for controlling virtualbox and your virtual servers. As I use it and make changes I will update the version available here. If you have any suggestions or features you would like to see added feel free to drop me an email also.