Overview of VirtualBox + phpvirtualbox
Ubuntu Server offers a free, open-source virtualization platform during OS installation. This platform, VirtualBox, is designed and maintained by Oracle. Since the Ubuntu Server installation is a command-line interface, managing the virtual machines is not always an easy task. In response to this, an independent developer released a web-based PHP user interface called phpVirtualBox to manage the VirtualBox VMs using your browser.
Ubuntu Server offers a free, open-source virtualization platform during OS installation. This platform, VirtualBox, is designed and maintained by Oracle. Since the Ubuntu Server installation is a command-line interface, managing the virtual machines is not always an easy task. In response to this, an independent developer released a web-based PHP user interface called phpVirtualBox to manage the VirtualBox VMs using your browser.
VirtualBox
is an open-source desktop virtualization solution that can be used in
production environments at the expense of being required to support your
own implementation. In combination with phpVirtualBox, management
of your virtual machines will be significantly easier for those who are
not trained/experienced in command-line interface.
Installing VirtualBox + phpvirtualbox
This guide will provide directions on installing VirtualBox + phpvirtualbox on a fresh installation of Ubuntu 14.04 Server LTS. This is one of the most lightweight implementations. You are free to configure your installation on a variety of different Linux distros, however, it is likely the commands will be different.
PREREQUISITES
STEP ONE [Installing necessary software]
Installing VirtualBox:
$ wget http://download.virtualbox.org/virtualbox/4.3.12/virtualbox-4.3_4.3.12-93733~Ubuntu~raring_amd64.deb
$ sudo dpkg -i virtualbox-4.3_4.3.12-93733~Ubuntu~raring_amd64.deb
$ sudo reboot
The VirtualBox expansion pack should be installed automatically. Let's verify:
$ sudo vboxmanage list extpack
This guide will provide directions on installing VirtualBox + phpvirtualbox on a fresh installation of Ubuntu 14.04 Server LTS. This is one of the most lightweight implementations. You are free to configure your installation on a variety of different Linux distros, however, it is likely the commands will be different.
PREREQUISITES
- Fresh installation of Ubuntu 14.04 Server LTS
- Static IP address (setting up static IP address in Ubuntu)
STEP ONE [Installing necessary software]
Installing VirtualBox:
$ wget http://download.virtualbox.org/virtualbox/4.3.12/virtualbox-4.3_4.3.12-93733~Ubuntu~raring_amd64.deb
$ sudo dpkg -i virtualbox-4.3_4.3.12-93733~Ubuntu~raring_amd64.deb
$ sudo reboot
The VirtualBox expansion pack should be installed automatically. Let's verify:
$ sudo vboxmanage list extpack
If the Extension Pack is not listed, please install it with the following commands:
$ wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
$ sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
NOTE: This guide is under the assumption you are on a fresh installation of Ubuntu 14.04 Server LTS. If you already have VirtualBox installed, please make sure that the vboxweb-service is installed. If you do not see the output of "vboxweb-service" from running the following command, you will most likely need to re-install your VirtualBox installation.
$ sudo ls /etc/init.d | grep vboxweb-service
$ wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
$ sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
NOTE: This guide is under the assumption you are on a fresh installation of Ubuntu 14.04 Server LTS. If you already have VirtualBox installed, please make sure that the vboxweb-service is installed. If you do not see the output of "vboxweb-service" from running the following command, you will most likely need to re-install your VirtualBox installation.
$ sudo ls /etc/init.d | grep vboxweb-service
Installing Apache2 + phpVirtualBox:
$ sudo apt-get install apache2 php5 libapache2-mod-php5 unzip
$ wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-4.3-1.zip
$ sudo unzip phpvirtualbox-4.3-1.zip -d "/var/www" && sudo mv /var/www/phpvirtualbox-4.3-1 /var/www/phpvirtualbox
STEP TWO [Configuring/completing your installation]
Before we can finish configuring phpVirtualBox, we need to create a dedicated account that phpVirtualBox can use to control VirtualBox. In this example, I will be using the username vbox.
$ sudo adduser -m vbox -G vboxusers
$ sudo passwd vbox
Finally, we want to edit the configuration of phpVirtualBox and VirtualBox with this information.
$ sudo mv /var/www/phpvirtualbox/config.php-example /var/www/phpvirtualbox/config.php
$ sudo vi /var/www/phpvirtualbox/config.php
Update the fields as follows:
/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'your_password_here';
/* SOAP URL of vboxwebsrv (not phpVirtualBox's URL) */
var $location = 'http://localhost:18083/';
Additionally, if you would like to disable username authentication:
/* Disable authentication */
var $noAuth = true;
These variables may require some tweaking depending on your environment. For more information, please visit the phpVirtualBox configuration section on their Wiki.
$ sudo apt-get install apache2 php5 libapache2-mod-php5 unzip
$ wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-4.3-1.zip
$ sudo unzip phpvirtualbox-4.3-1.zip -d "/var/www" && sudo mv /var/www/phpvirtualbox-4.3-1 /var/www/phpvirtualbox
STEP TWO [Configuring/completing your installation]
Before we can finish configuring phpVirtualBox, we need to create a dedicated account that phpVirtualBox can use to control VirtualBox. In this example, I will be using the username vbox.
$ sudo adduser -m vbox -G vboxusers
$ sudo passwd vbox
Finally, we want to edit the configuration of phpVirtualBox and VirtualBox with this information.
$ sudo mv /var/www/phpvirtualbox/config.php-example /var/www/phpvirtualbox/config.php
$ sudo vi /var/www/phpvirtualbox/config.php
Update the fields as follows:
/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'your_password_here';
/* SOAP URL of vboxwebsrv (not phpVirtualBox's URL) */
var $location = 'http://localhost:18083/';
Additionally, if you would like to disable username authentication:
/* Disable authentication */
var $noAuth = true;
These variables may require some tweaking depending on your environment. For more information, please visit the phpVirtualBox configuration section on their Wiki.
Once you have completed editing your phpVirtualBox config, we want to edit the VirtualBox configuration.
$ sudo vi /etc/default/virtualbox
Add the following line:
VBOXWEB_USER=vbox
$ sudo vi /etc/default/virtualbox
Add the following line:
VBOXWEB_USER=vbox
To finalize your installation, restart the services with the following command:
$ sudo service apache2 restart && sudo service vboxweb-service restart
STEP THREE [Testing/optimizing your installation]
Congratulations! Your installation should be completed. To verify it is working, please visit:
http://your_IP_address/phpvirtualbox
You should be greeted with a "Username" and "Password" Log in window:
Default username: admin
Default password: admin
$ sudo service apache2 restart && sudo service vboxweb-service restart
STEP THREE [Testing/optimizing your installation]
Congratulations! Your installation should be completed. To verify it is working, please visit:
http://your_IP_address/phpvirtualbox
You should be greeted with a "Username" and "Password" Log in window:
Default username: admin
Default password: admin
At this point, everything should be working. You're done!
OPTIONAL CONFIGURATION(S)
Enabling HTTPS / SSL:
The picture above is my current installation. If you look carefully, you will notice that I am using a self-signed SSL certificate (HTTPS) operating on port 8443. If you would like to install a self-signed certificate as well, please following the instructions below:
[Create self-signed SSL certificate]
$ sudo make-ssl-cert generate-default-snakeoil --force-overwrite
[Activate Apache SSL module]
$ sudo a2enmod ssl
[Activate Apache default SSL virtual host]
$ sudo a2ensite default-ssl
[Disable HTTP listening port]
$ sudo vi /etc/apache2/ports.conf
(Remove "Listen 80" to disable listening on port 80)
The picture above is my current installation. If you look carefully, you will notice that I am using a self-signed SSL certificate (HTTPS) operating on port 8443. If you would like to install a self-signed certificate as well, please following the instructions below:
[Create self-signed SSL certificate]
$ sudo make-ssl-cert generate-default-snakeoil --force-overwrite
[Activate Apache SSL module]
$ sudo a2enmod ssl
[Activate Apache default SSL virtual host]
$ sudo a2ensite default-ssl
[Disable HTTP listening port]
$ sudo vi /etc/apache2/ports.conf
(Remove "Listen 80" to disable listening on port 80)
[Disable default Apache site]
$ sudo a2dissite 000-default
[Update default-ssl Apache site]
$ sudo vi /etc/apache2/sites-available/default-ssl.conf
(Update port if you are not using 443. Update DocumentRoot if you want IP address to resolve without /phpvirtualbox)
$ sudo a2dissite 000-default
[Update default-ssl Apache site]
$ sudo vi /etc/apache2/sites-available/default-ssl.conf
(Update port if you are not using 443. Update DocumentRoot if you want IP address to resolve without /phpvirtualbox)
Launching VMs on Startup / Saving VMs on Shutdown:
One disadvantage of VirtualBox is that VirtualBox is technically "desktop virtualization" software and is not intended for production use. In the event of a reboot or power failure on your server, the VirtualBox VMs will not natively run on start-up. This can be easily fixed with a simple /etc/init.d/ script, compliments of capdragon's post on askubuntu.com.
$ sudo vi /etc/init.d/StartVM
Paste the following code:
#! /bin/sh
# /etc/init.d/StartVM
#Edit these variables!
VMUSER=vbox
VMNAME="YOUR VM NAME"
case "$1" in
start)
echo "Starting VirtualBox VM..."
cd
sudo -H -b -u $VMUSER /usr/bin/VBoxManage startvm "$VMNAME" --type headless
sleep 3
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
sleep 3
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac
exit 0
One disadvantage of VirtualBox is that VirtualBox is technically "desktop virtualization" software and is not intended for production use. In the event of a reboot or power failure on your server, the VirtualBox VMs will not natively run on start-up. This can be easily fixed with a simple /etc/init.d/ script, compliments of capdragon's post on askubuntu.com.
$ sudo vi /etc/init.d/StartVM
Paste the following code:
#! /bin/sh
# /etc/init.d/StartVM
#Edit these variables!
VMUSER=vbox
VMNAME="YOUR VM NAME"
case "$1" in
start)
echo "Starting VirtualBox VM..."
cd
sudo -H -b -u $VMUSER /usr/bin/VBoxManage startvm "$VMNAME" --type headless
sleep 3
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
sleep 3
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac
exit 0
Now, we want to make this script executable as well as have it run first on shutdown and last on start up.
$ sudo chmod +x /etc/init.d/StartVM
$ sudo update-rc.d StartVM defaults 99 01
$ sudo chmod +x /etc/init.d/StartVM
$ sudo update-rc.d StartVM defaults 99 01
For those of you still reading, thank you very much for reading my blog! Hopefully this has been helpful and informative.
As always, good luck and happy scripting!
~ Miles
Tidak ada komentar:
Posting Komentar