Showing posts with label virtual box. Show all posts
Showing posts with label virtual box. Show all posts

Saturday, January 28, 2012

A web interface for Virtualbox: phpvirtualbox

The previous article ( was about creating a virtual machine with VBoxManage command. I must confess that using that VBoxManage command to manage Virtualbox machines is not easy. A web interface would be easier than using command-line. There are some alternatives to get it. The first one is The Software Developer Kit. You can download it from address. This package contains all required tools and libraries, If your aim is to develop..

But I'm going to talking about phpvirtualbox project which is hosted on site. The web address of this project is "". You can download the project from this site or help to develop more and you may want to support it. Finally, it's realy useful and capable to manage the Virtualbox structure. I want to talk about this project which is ready for use after then my previos two entries of course.

1-) Apache http server installation.

support@tester:~$ sudo apt-get install apache2 php5
[sudo] password for support:
Do you want to continue [Y/n]?
Setting up php5 (5.3.6-13ubuntu3.3) ...
Setting up php5-cli (5.3.6-13ubuntu3.3) ...

Creating config file /etc/php5/cli/php.ini with new version
update-alternatives: using /usr/bin/php5 to provide /usr/bin/php (php) in auto mode.
Setting up ssl-cert (1.0.28) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

If you want to check the installation you can create a "test.php" file in the /var/www/ directory as shown below:

<?php phpinfo(); ?>

Now you will able to see all information about your completed setup of Php.

2-) Downloading and extracting Phpvirtualbox package.

support@tester:~$ wget
support@tester:~$ sudo apt-get install unzip
support@tester:~$ unzip
support@tester:~$ sudo cp -R phpvirtualbox-4.1-7 /var/www/phpvirtualbox

Right now, we have to rename "config.php-example" file and edit it. It is the configuration file of Phpvirtualbox.

support@tester:~$ cd /var/www/phpvirtualbox/
support@tester:/var/www/phpvirtualbox$ sudo mv config.php-example config.php

Edit 12th, 13th and 52th lines as shown below:

  1 <?php
2 /**
3 * phpVirtualBox example configuration.
4 * @version $Id: config.php-example 366 2011-12-01 19:56:57Z $
5 *
6 * rename to config.php and edit as needed.
7 *
8 */
9 class phpVBoxConfig {
11 /* Username / Password for system user that runs VirtualBox */
12 var $username = 'support';
13 var $password = '[password_of_support]';
51 // Disable authentication
52 var $noAuth = true;

3-) Starting vboxwebsrv service and accessing to phpvirtualbox interface.

support@tester:~$ sudo touch /var/log/vboxwebsrv.log
support@tester:~$ sudo chown support /var/log/vboxwebsrv.log
support@tester:~$ vboxwebsrv -b -F /var/log/vboxwebsrv.log
Oracle VM VirtualBox web service version 4.1.8
(C) 2005-2011 Oracle Corporation
All rights reserved.
VirtualBox web service 4.1.8 r75467 linux.amd64 (Dec 19 2011 14:49:48) release log
00:00:00.000 main Log opened 2012-01-27T20:52:43.870809000Z
00:00:00.000 main OS Product: Linux
00:00:00.000 main OS Release: 3.0.0-12-server
00:00:00.000 main OS Version: #20-Ubuntu SMP Fri Oct 7 16:36:30 UTC 2011
00:00:00.000 main OS Service Pack: #20-Ubuntu SMP Fri Oct 7 16:36:30 UTC 2011
00:00:00.000 main Executable: /usr/lib/virtualbox/vboxwebsrv
00:00:00.000 main Process ID: 19407
00:00:00.000 main Package type: LINUX_64BITS_UBUNTU_11_10

-b parameter is for starting the service in the background and -F parameter is for creating a log file "/var/log/vboxwebsrv.log". The problem is, the user support has not rights to create a log file in the "/var/log" directory. So we created it as root and gave the ownership to support again in top two command. If we need a startup script to auto start when base system is booting, we have to have the caseful ownership part as below, (/etc/init.d/vboxwebsrv_starter)


u=`/usr/bin/id -u`

case "$1" in
if [ $u -eq 0 ]; then
/bin/su support -c '/usr/bin/vboxwebsrv -b -F /var/log/vboxwebsrv.log'
echo "Start vboxwebsrv"
/usr/bin/vboxwebsrv -b -F /var/log/vboxwebsrv.log
# nothing
# commands for restarting will come here then...hah?
# ..
echo "vboxwebsrv:";
/bin/ps -ef | /bin/grep vboxwebsrv
echo "Usage: /etc/init.d/vboxwebsrv_starter [start|stop|restart|status]"
exit 1
exit 0

Finally, we have to give execute permissions and add inittab with update-rc.d command as shown below:

support@tester:~$ sudo chmod +x /etc/init.d/vboxwebsrv_starter
support@tester:~$ sudo update-rc.d vboxwebsrv_starter defaults
update-rc.d: warning: /etc/init.d/vboxwebsrv_starter missing LSB information
update-rc.d: see <>
Adding system startup for /etc/init.d/vboxwebsrv_starter ...
/etc/rc0.d/K20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc1.d/K20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc6.d/K20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc2.d/S20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc3.d/S20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc4.d/S20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter
/etc/rc5.d/S20vboxwebsrv_starter -> ../init.d/vboxwebsrv_starter

4-) You can select a Virtualbox based password protection or Apache based password protection to access to Phpvirtualbox directory.

a) Edit sudo vim /etc/apache2/sites-enabled/000-default file to get ready to password protection on apache. I added "+" lines to 000-default file as shown below:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

+ <Directory /var/www/phpvirtualbox>
+ Options Indexes FollowSymLinks MultiViews
+ AllowOverride AuthConfig
+ Order allow,deny
+ allow from all
+ </Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

b) Create a user and a password with "htpasswd" command as shown below:

support@tester:~$ htpasswd -c /home/support/passwords vboxuser
New password:
Re-type new password:
Adding password for user vboxuser

The "-c" parameter is for creating a new file which contains both user and password information.

c) Create "access" file in the password protected directory. Save following content in /var/www/phpvirtualbox/.htaccess file.

AuthType Basic
AuthName "Virtualbox Management Interface"
AuthUserFile /home/support/passwords
Require user vboxuser

Finally we have to reload / restart apache service to apply changes as shown below:

support@tester:~$ sudo /etc/init.d/apache2 restart

Note: This article about just installation. I'll talk about authentication and multiple user configuration. This feature supply different virtual machines lists for each other user.