Linux防健忘日誌No.82-Ubuntu 12.04.4 安裝phpVirtualBox,利用網頁來管理VirtualBox

最近想把魔爪延伸到虛擬化身上,先前有玩過ESXi這種專業級的os virtualization的虛擬化平台

 

但最後還是換回Ubuntu,一來是沒有正版授權,二來是沒到那個規模,但要研究很多東西,對於業餘來說有點脫褲子放屁

 

 

先前有配上libvirt+WebVirtMgr(是一個用python寫成的虛擬機器WebUI)

但不知道為什麼莫名其妙裝好兩個月之後無預警死掉

 

嘗試修復好幾次未果,所以就放棄他…

 

今天東摸摸西摸摸看到VirtualBox可以配上社群開發的phpVirtualBox完成WebUI的SOLUTION,感覺蠻優的

 

就找了一下作法,本篇主要是翻譯自:https://www.youtube.com/watch?v=6UHD0SIL-RM

內的作法並且針對Ubuntu 12.04.04 LTS以及VirtualBox 4.3做微調(原文為Ubuntu 13.04配上VirtualBox 4.2)

但大致上沒有任何邏輯變動的部分,只有稍微改一下套件以合適我的平台環境。

 

 

前置條件:裝好Apache等Web Service,這點我不覆述了,我網誌也有裝Apache的方法

 

 

首先你要先搞定好VirtualBox,在沒有圖形化介面的情況下可以用apt-get的套件指令來安裝

參考:http://linuxg.net/how-to-install-virtualbox-4-3-on-ubuntu-13-04-12-10-12-04-linux-mint-15-14-13-pear-os-8-pear-os-7-and-elementary-os-0-2-via-the-official-virtualbox-repository/

但各版本比較有差別的只有在source list的contrib描述不一樣而已

 

先加pgp公鑰:

wget -q -O – http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc | sudo apt-key add –

 

把virtualbox加入套件庫來源:

sudo sh -c ‘echo “deb http://download.virtualbox.org/virtualbox/debian precise non-free contrib” >> /etc/apt/sources.list.d/virtualbox.org.list’

 

更新套件庫並且安裝virtualbox 4.3:

sudo apt-get update

sudo apt-get install virtualbox-4.3

 

 

接著要裝上extension package

這邊依照你的版本來選擇,這裡是安裝VirtualBox 4.3.10,所以到官方網站下http://download.virtualbox.org/virtualbox/4.3.10/

若你不知道你詳細的版本號,可以打virtualbox –help | head -n 3,第一行通常就有詳細的版本編號

 

抓到對應的extension package:

Oracle_VM_VirtualBox_Extension_Pack-4.3.10-93012.vbox-extpack

 

接著要透過VBoxManage 把該extension pack給裝起來:

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.10-93012.vbox-extpack

 

創立一個virtualbox網路服務的帳號

sudo vim /etc/default/virtualbox

裡面放入一行(這個vbox可以自定義,但接下來要新增user的時候就要跟著變)

VBOXWEB_USER=vbox

 

儲存離開。

 

然後創建剛剛準備給virtualbox屬用網路服務的帳號:

sudo useradd -m vbox -G vboxusers

sudo passwd vbox

 

為確保你的apache有裝妥以及php版本足夠,還是請下一下以下指令:

sudo apt-get install apache2 php5 libapache2-mod-php5

 

 

接下來就要開始安裝phpVirtualBox的UI了,首先要先拿到新版的phpVirtualBox

但很弔詭的是最新的版本在sourceforge.net居然是4.2…但其實4.3已經在上面,估計是沒有調整的關係

所以如果你的VirtualBox是4.3,就必須搭配4.3的phpVirtualBox

 

原文是寫:wget -O download.zip http://sourceforge.net/projects/phpvirtualbox/files/latest/download

但我們這邊要抓取4.3的,依照上面的連結撰文期間抓下來的會是4.2…

所以要做點微調:wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-1.zip/download

 

解壓縮(請自行安裝unzip套件):

unzip phpvirtualbox-4.3-1.zip

 

接著把整個phpvirtualbox的資料夾移動到www底下:

sudo mv phpvirtualbox-4.3-1 /var/www/phpvirtualbox

 

然後要把最重要的phpvirtualbox的config.php複製出來,並且編輯之:

sudo cp /var/www/phpvirtualbox/config.php-exampl­e /var/www/phpvirtualbox/config.php

sudo vi /var/www/phpvirtualbox/config.php

 

文件內前面就可以看到

var $username = ‘vbox’;

var $password = ‘pass’;

 

 

password的部分就改成你剛剛建立vbox使用者的密碼,但這邊要注意,因為該文件為明碼儲存,所以請把這個config.php的權限設置妥當

 

儲存離開,並且重啟伺服器(因為原文作者說不重啟的話無法存取VM的RDP)

 

接著你就可以在瀏覽器打入:

http://你的伺服器ip/phpvirtualbox

 

看到登入頁面,初始化的帳號密碼都是admin,接下來的操作就跟在GUI底下使用VirtualBox的手續一樣了。

 

 

以上

 

===============================================

以下是youtube註解,我是直接複製下來作為條翻譯的,有需要原文者也可以參考

 

Some text, not commands, omitted because it’s too long. ## This is a short video explaining how you can setup a web-based user interface for VirtualBox on your Ubuntu box. This will be demonstrated on an Ubuntu Server 13.04 x64 VM. Other distributions may slightly differ, but you can still use this video as a quick reference.

 

Installing dependencies for painless kernel upgrades: sudo apt-get install dkms # I’ve already done this when I installed the VirtualBox Guest Additions.

 

Adding VirtualBox to your repositories: sudo sh -c ‘echo “deb http://download.virtualbox.org/virtualbox/debian raring contrib” ?? /etc/apt/sources.list.d/virtualbox.list’

 

IMPORTANT: Replace the question marks with “greater-than” symbols in the command above. YouTube doesn’t allow that character in the description.

 

NOTE: The command above is for Ubuntu 13.04 only! If you’re using a different version, or a different distro all together, you should see the installation details on the VirtualBox official website for more information.

 

Adding the Oracle public key: wget -q http://download.virtualbox.org/virtua… -O- | sudo apt-key add –

 

Installing VirtualBox: sudo apt-get update && sudo apt-get install virtualbox-4.2

 

Download the VirtualBox Extension Pack: wget http://download.virtualbox.org/virtualbox/4.2.4/Oracle_VM_VirtualBox_Extension_Pack-4.2.4-81684.vbox-extpack

 

Install the VirtualBox Extension Pack: sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.4-81684.vbox-extpack

 

NOTE: The two commands above can be different if you’re installing a newer version of version than 4.2.18. To determine which version you have, run “virtualbox –help | head -n 3”

 

Create the /etc/default/virtualbox file: sudo vim /etc/default/virtualbox

Edit vboxweb-service:

VBOXWEB_USER=vbox

 

IMPORTANT: The user above must exist on the system. You can create a seperate service account with a long, complex and randomly generated password for security purposes.

 

NOTE: The /etc/default/virtualbox can be further customized. See the link under “More information” for more information.

 

Create the new user: sudo useradd -m vbox -G vboxusers

Assign the new user a password: sudo passwd vbox

Installing a webserver for pvpVirtualBox: sudo apt-get install apache2 php5 libapache2-mod-php5

 

Downloading the latest phpVirtualBox: wget -O download.zip http://sourceforge.net/projects/phpvirtualbox/files/latest/download

 

Install unzip: sudo apt-get install unzip

 

Unzip the package: unzip download.zip

 

Move the folder to the webserver: sudo mv phpvirtualbox-4.2-7 /var/www/phpvirtualbox

 

NOTE: The previous command might be slightly different of you downloaded a newer version.

 

Copy the config.php-example file: sudo cp /var/www/phpvirtualbox/config.php-exampl­e /var/www/phpvirtualbox/config.php

 

Edit the new config.php file: sudo vim /var/www/phpvirtualbox/config.php

var $username = ‘vbox’;

var $password = ‘pass’;

 

IMPORTANT: Change the above credentials to match the credentials for the user account you provided in the “/etc/default/virtualbox” file. For security concerns, you might want to change the permissions on the config.php file as well.

 

Restart the server: sudo reboot

 

NOTE: I found that I couldn’t access the remote display of VMs from the browser until I rebooted. It might have something to do with the expansion pack that requires a reboot, but I’m not to sure about that…

 

Open a webbrowser and login in with admin/admin

 

NOTE: You may notice I use the following link: localhost:9000. This is unique to my system, because I use VirtualBox NAT port forwarding. You may be better off with just localhost. If you’re on another system, use the real IP of the server.

 

Change the admin password for security purposes and create a new one for yourself.

 

I’ll demonstrate a VM with Damn Small Linux. I’m not going to start a full fledged Ubuntu VM here, because my server is actually a VirtualBox itself. I tried it, and it does work, but it’s way too slow here. My advise, use this on a real system, not a virtualized one!

 

IMPORTANT: When you create your first VM and you want to access it, you may notice it doesn’t capture the mouse as well. To fix this, install the VirtualBox Guest Additions and it goed away!

 

I don’t know if I can install the Guest Additions in DSL. I could try, but I probably would have to install it first and I’m not going to now. This is just a demonstration.

 

Again, I do apologize for the crappy demo, but for obvious reasons…

Leave a comment

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料