Wednesday, March 28, 2012

How to Connect SQLite Database in Android & A Simple App: "Accessing Data With Android Cursors"

Hi Everyone! I'd showed you how to do an application on Android in the last article. This one is going to be about connection SQLite database and access data with cursors.

If you want to use your data or something else, should connect a database. Using SQLite on Android is so simple. There are so much SQLite Editor but I will use Firefox SQLite Manager in this article. For that, first open your Firefox Browser, then download SQLite Manager and as result go this directory: Tools/SQLite Manager. After that, you can range database. 

And now, it's time to ready our files we use to. Just follow this directories:


Documents:
1- src/DatabaseActivity.java
2- src/Database.java
3- layout/data.xml

We need "database.java" file, that's why is gotta a table on database. If you want to add something, I must have a database. Now, code Database.java file.
package database.connection;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class Database extends SQLiteOpenHelper {
 private static final String MYDATABASE = "names";
 private static final int VERSION = 1;

 public Database(Context connection) {
  super(connection, MYDATABASE, null, VERSION);
 }

 @Override
 public void onCreate(SQLiteDatabase db) {
  db.execSQL("CREATE TABLE mynames(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);");
 }

 @Override
 public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
  db.execSQL("DROP TABLE IF EXIST mynames");
  onCreate(db);
 }
}

So, we've just created a database, as called MYDATABASE. Table's name is "names". There are two fields on it: "id and name". As you know that is all about SQL. If you know SQL, you can get it easily. id field is an integer piece of table. The other one is a text field.

We'got a database and a table of this. The form we can add data is what we need exactly. For that, gotta compose a Android XML File. This file will have a textfield widget and a button widget, that's it! Let's do data.xml file!


    
        
    

    

If you want, just look what we got up right now. We created a database, a table of this database and form widgets. I can add a data after make this platform up:) Let's do our platform: DatabaseActivity.java file
package database.connection;
//Those are included by the system 
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 
public class DataBaseActivity extends Activity {
    private DB names;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.data); //including layout/data.xml file
        names = new DB(this);
        final EditText name=(EditText) findViewById(R.id.editText1);
 
        Button senddata=(Button) findViewById(R.id.senddata);
 
        senddata.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
                    try{
                     AddDATA(name.getText().toString());
                     Cursor cursor = ShowDATA();
                     ShowDATA(cursor);
                     }
                     finally{
                     names.close();
                    }
            }
        });
 
    }
    
    private void AddDATA(String ResultName){

    SQLiteDatabase db = names.getWritableDatabase();
    ContentValues datas = new ContentValues();
    datas.put("name", ResultName);
    db.insertOrThrow("ournames", null, datas);
    }

    private String[] SELECT = {"id", "name"};

    private Cursor ShowDATA(){
    SQLiteDatabase db = names.getReadableDatabase();
    Cursor cursor = db.query("ournames", SELECT, null, null, null, null, null);

    startManagingCursor(cursor);
    return cursor;
    }

    private void ShowDATA(Cursor cursor){
        StringBuilder builder = new StringBuilder("RESULTS!:\n");

        while(cursor.moveToNext()){

        String whatthenameis = cursor.getString((cursor.getColumnIndex("name")));
        builder.append(whatthenameis).append("\n");
        }

        TextView text = (TextView)findViewById(R.id.textView1);
        text.setText(builder);
    }
}
Generally, coder need to use a database, while saving data. We use SQLite Database on Android'cuz it's simple. Here, SQL is as you know before. "SELECT" command using also. By the way, if you want to check your db file out, just go this directory on Eclipse: file explorer/data/[your project name]/database
Write Something
That's it! We can add and save our datas, through SQLite Database on Android.
When you write something and click button, data will been saved and can show it on the screen. We'll you guys next article!

Saturday, March 10, 2012

Developing a Basic Application on Android: "Welcome Page"

Hi Everyone! Today, I'll show you an Android application which is about welcome pages. As known, before when opened an app, game, web site, DVD movie, etc, a welcome page has shown us by masters of'em. That's why is showing what the brand is. For example, Angry Birds, EA Games, Microsoft Games.

This article is going to be a basic application like "Hello World!". But Before we'll be on welcome page and see the welcome message on it. Let's see how to do it!

Necessary equipment (Install all of them)
  1. Eclipse Editor
  2. SDK (Software Development Kid)
  3. Android: WindowsLinuxMac
First, open the Eclipse editor, then follow this directory: File/New/Project/Android/Android Project
My Project Name : WelcomePage
My Android Version : V2.2
My Package Name : welcome.page
You can fix this properties as you wish.

I think, you know how to do an "hello world" app on Android, so I won't explain this. The important thing of the app for me is relationship of Activities and Threads. For those, we're going to do this pages:
src/WelcomePageActivity.class //This is a default file
src/WelcomePage.class
res/layout/main.xml //This is also a default file
res/layout/page2.xml
AndroidManifest.xml //This is configuration file
Create a class file: 
  1. directory: src/(Right Click)New/Class
  2. call: WelcomePage
  3. Click the "Finish" Button
Code for WelcomePage.java:
package welcome.page;

import android.app.Activity;
import android.os.Bundle;

public class WelcomePage extends Activity { //Created WelcomePage Activity
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main); //The content to display from main.xml
 }
}

The "R" is a library which used for xml files. Every xml file can used on it. We'd just used main.xml file for we need to go home page of our Android app after showing welcome page.

Create a xml file:
  1. directory: res/layout/(Right Click)Other/File/Android/Android Xml File
  2. call: page2
  3. Click the "Finish" Button
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a welcome page!" />

</LinearLayout>

When we look at this page up, should see like that:
page2.xml file view
Create WelcomePageActivity.java file
package welcome.page;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class WelcomePageActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page2); //The content to display from page2.xml file
        
        Thread WelcomeScreen = new Thread() { //Must create a thread, because opening another page is a different event, as sync
         public void run() {
          try { //This is try-catch
           sleep(5000); //Waiting five seconds
           startActivity(new Intent(getApplicationContext(),WelcomePage.class)); 
           //After waiting, shown the content from WelcomePage.java file
          } catch (InterruptedException e) {
           e.printStackTrace();
          }
          finally {
           finish(); //We finish this thread.
          }
         }
        };
        WelcomeScreen.start(); //Starting the thread created.
    }
}

Maybe, you may not get the line, 
"startActivity(new Intent(getApplicationContext(),WelcomePage.class));". 
Just remember that we used main.xml content to get on WelcomePage.java page.

And the last one we have to do, update AndroidManifest.xml file! Remember that we create a new Activity, so must define this Activity. For that reason, just add this code to AndroidManifest.xml file:
And yes, finished! Let's work this on our Emulator! For this, call: 


WelcomePage Project(Right Click)/Run as/Android Project

Welcome page view
After 5 seconds this page, we will see main.xml file:

main.xml file on my application
We'll see you guys next article!

Wednesday, February 1, 2012

Making bootable Slax Usb in Ubuntu

It is a problem to make a bootable USB flash disk in Ubuntu as I see in the Slax Forums. Slax can be installed in a Fat formatted USB disk or a CD-Rom. However, for the need for compactness, people generally chooses the first option in order to use an "install once and use anywhere" operating system.

Unfortunately, if you are using an Ubuntu OS and you want to make a Slax Bootable USB, problem arises. Since the USB must be formatted as FAT, you can not change the owners and permissions of files and directories. So that, we can not set a file executable. And simply writing a

usbdisk/boot> bash bootinst.sh

command cannot handle the problem. But the solution is easy.

First, download the Slax tar file for USB disks. Untar it. You have two folders. One of them is 'slax' and the other is 'boot'. Copy the 'boot' folder in your harddisk. Write

harddisk/some folder/boot> chmod -R a+x *

So, the copied boot folder is now fully executable. Suppose that  the 'some folder' is '/usr/local/bin'. Goto usb disk. Change directory to 'boot'. Edit the bootinst.sh

usbdisk> vim bootinst.sh


And change the content of the bootinst.sh file as following:



#!/bin/bash

set -e
TARGET=""
MBR=""

# Find out which partition or disk are we using
MYMNT=$(cd -P $(dirname $0) ; pwd)
while [ "$MYMNT" != "" -a "$MYMNT" != "." -a "$MYMNT" != "/" ]; do
   TARGET=$(egrep "[^[:space:]]+[[:space:]]+$MYMNT[[:space:]]+" /proc/mounts | cut -d " " -f 1)
   if [ "$TARGET" != "" ]; then break; fi
   MYMNT=$(dirname "$MYMNT")
done

if [ "$TARGET" = "" ]; then
   echo "Can't find device to install to."
   echo "Make sure you run this script from a mounted device."
   exit 1
fi

if [ "$(cat /proc/mounts | grep "^$TARGET" | grep noexec)" ]; then
   echo "The disk $TARGET is mounted with noexec parameter, trying to remount..."
   mount -o remount,exec "$TARGET"
fi

MBR=$(echo "$TARGET" | sed -r "s/[0-9]+\$//g")
NUM=${TARGET:${#MBR}}
cd "$MYMNT"

clear
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "                        Welcome to Slax boot installer                         "
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo
echo "This installer will setup disk $TARGET to boot only Slax."
if [ "$MBR" != "$TARGET" ]; then
   echo
   echo "Warning! Master boot record (MBR) of $MBR will be overwritten."
   echo "If you use $MBR to boot any existing operating system, it will not work"
   echo "anymore. Only Slax will boot from this device. Be careful!"
fi
echo
echo "Press any key to continue, or Ctrl+C to abort..."
read junk
clear

echo "Flushing filesystem buffers, this may take a while..."
sync

# setup MBR if the device is not in superfloppy format
if [ "$MBR" != "$TARGET" ]; then
   echo "Setting up MBR on $MBR..."
   /usr/local/bin/syslinux/lilo -S /dev/null -M $MBR ext # this must be here to support -A for extended partitions
   echo "Activating partition $TARGET..."
   /usr/local/bin/syslinux/lilo -S /dev/null -A $MBR $NUM
   echo "Updating MBR on $MBR..." # this must be here because LILO mbr is bad. mbr.bin is from syslinux
   cat /usr/local/bin/syslinux/mbr.bin > $MBR
fi

echo "Setting up boot record for $TARGET..."
  /usr/local/bin/syslinux/syslinux -d boot/syslinux $TARGET

echo "Disk $TARGET should be bootable now. Installation finished."

echo
echo "Read the information above and then press any key to exit..."
read junk 
 
 
Save the file. Exit to shell. Type

usbdisk/boot> sudo bash bootinst.sh


By now, bootinst.sh runs the needed commands from /usr/local/bin not from /usbdisk/boot.


Happy installs...

Tuesday, January 31, 2012

A tiny C library for client sockets

Sockets are everything in programming, especially, after the wide use of internet. Sockets are used for connecting two devices in a network using several low level protocols. At user level, those protocols are not transparent to user, that is, opening a connection and sending some string or binary data along a network is the whole thing for a general programmer.

Socket programming is not a difficult one in much of high level languages. I have used sockets in Java several times and the stuff were running like a charm. Unfortunately, same easiness is not current for C. However, it is the faster way of doing this work.

Last day, I needed to code a client socket for retrieving some data over the network. My Ubuntu was ready for the task with its installed C libraries. Since Linux sockets are a little bit detailed so there were too many terms (htons, inet_ntoa) which requires some low level knowledge of Linux sockets. For example, a C# programmer does not need to know how Windows converts an IP number to binary data and via versa. But Linux sockets are harder. But once you learn it, it is more fun.

Finally, I wrote a small library for a client socket task. The example of this code is shown below:

(Test.c)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "ClientSocket.h"
  5.  
  6.  
  7. int main(int argc, char** argv) {
  8. /* We will store some text in this buffer */
  9. int bufsize=1024;
  10. char buffer[bufsize];
  11. char *hostname = "blogspot.com";
  12. int port = 80;
  13. /* Getting ip address of google.com into buffer */
  14. getIPAddress("google.com", buffer);
  15. printf("Connecting to (%s) %s\n", hostname, buffer);
  16. /* Creating socket */
  17. struct ClientSocket *socket = socket_create(buffer, port);
  18. /* Connecting */
  19. socket_connect(socket);
  20. /* Sending a http request */
  21. strcpy(buffer,"GET /\n\n");
  22. socket_send(socket, buffer, strlen(buffer));
  23. /* Receiving the first #bufsize elements */
  24. socket_receive(socket, buffer, bufsize);
  25. printf("%s",buffer);
  26. /* Do not read any more. Closing */
  27. socket_close(socket);
  28. return (EXIT_SUCCESS);
  29. }
  30.  
 



The header file of out tiny library is here:(ClientSocket.h)
  1. /*
  2. * File: ClientSocket.h
  3. * Author: Practical Code Solutions
  4. *
  5. * Created on January 31, 2012, 9:56 AM
  6. */
  7.  
  8. #ifndef CLIENTSOCKET_H
  9. #define CLIENTSOCKET_H
  10.  
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14.  
  15. struct ClientSocket {
  16. int fd;
  17. char *ip;
  18. int port;
  19. int (*getIp)(const char *, char *);
  20. };
  21.  
  22. int getIPAddress(const char *host, char *ip);
  23.  
  24. struct ClientSocket *socket_create(char *ip, int port);
  25.  
  26. int socket_connect(struct ClientSocket *sock);
  27.  
  28. int socket_send(struct ClientSocket *sock, char *data, int len);
  29.  
  30. int socket_receive(struct ClientSocket *sock, char *data, int len);
  31.  
  32. int socket_close(struct ClientSocket *sock);
  33.  
  34.  
  35.  
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39.  
  40. #endif /* CLIENTSOCKET_H */
  41.  
The C source file of our tiny library is here: (ClientSocket.c)
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #include <sys/socket.h>
  6. #include <netdb.h>
  7.  
  8. #include "ClientSocket.h"
  9.  
  10. int getIPAddress(const char *host, char *ip){
  11. struct hostent *hh = gethostbyname(host);
  12. struct in_addr *add = hh->h_addr_list[0];
  13. strcpy(ip, inet_ntoa(add[0]));
  14. }
  15.  
  16. struct ClientSocket *socket_create(char *ip, int port){
  17. struct ClientSocket *socket = malloc(sizeof(struct ClientSocket));
  18. socket->ip = ip;
  19. socket->port = port;
  20. socket->getIp = getIPAddress;
  21. return(socket);
  22. }
  23.  
  24. int socket_connect(struct ClientSocket *sock){
  25. struct sockaddr_in addr;
  26. int result;
  27. sock->fd = socket(AF_INET, SOCK_STREAM, 0);
  28. memset((char *)&addr, 0, sizeof(addr));
  29. addr.sin_port = htons(sock->port);
  30. addr.sin_family = AF_INET;
  31. addr.sin_addr.s_addr = inet_addr(sock->ip);
  32. result = connect(sock->fd, (struct sockaddr *)&addr, sizeof(addr));
  33. return(result);
  34. }
  35.  
  36. int socket_send(struct ClientSocket *sock, char *data, int len){
  37. return send(sock->fd, data, len, 0);
  38. }
  39.  
  40. int socket_receive(struct ClientSocket *sock, char *data, int len){
  41. data[len-1] = '\0';
  42. return recv(sock->fd, (void *)data, len -1 , 0);
  43. }
  44.  
  45. int socket_close(struct ClientSocket *sock){
  46. return close (sock->;fd);
  47. }

Saturday, January 28, 2012

A web interface for Virtualbox: phpvirtualbox



The previous article (http://stdioe.blogspot.com/2012/01/creating-virtual-machine-with.html) 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 http://download.virtualbox.org/virtualbox/4.1.8/VirtualBoxSDK-4.1.8-75467.zip 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 code.google.com site. The web address of this project is "http://code.google.com/p/phpvirtualbox/". 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
support@tester:~$

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 http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.1-7.zip
support@tester:~$ sudo apt-get install unzip
support@tester:~$ unzip phpvirtualbox-4.1-7.zip
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
support@tester:/var/www/phpvirtualbox$

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 imooreyahoo@gmail.com $
5 *
6 * rename to config.php and edit as needed.
7 *
8 */
9 class phpVBoxConfig {
10
11 /* Username / Password for system user that runs VirtualBox */
12 var $username = 'support';
13 var $password = '[password_of_support]';
14
...
...
51 // Disable authentication
52 var $noAuth = true;
53
...
...

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)

#!/bin/bash

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

case "$1" in
start)
if [ $u -eq 0 ]; then
/bin/su support -c '/usr/bin/vboxwebsrv -b -F /var/log/vboxwebsrv.log'
else
echo "Start vboxwebsrv"
/usr/bin/vboxwebsrv -b -F /var/log/vboxwebsrv.log
fi
;;
stop)
# nothing
;;
restart)
# commands for restarting will come here then...hah?
stop
start
;;
status)
# ..
echo "vboxwebsrv:";
/bin/ps -ef | /bin/grep vboxwebsrv
;;
*)
echo "Usage: /etc/init.d/vboxwebsrv_starter [start|stop|restart|status]"
exit 1
;;
esac
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 <http://wiki.debian.org/LSBInitScripts>
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
support@tester:~$

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>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

+ <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
</Directory>
...
....
......

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
support@tester:~$

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.