Here’s a tutorial that shows you how to install VirtualBox in CentOS 7 server and manage it via phpVirtualBox tool. With this setup you’ll be able to manage VirtualBox guest machines remotely via a web browser. This setup is also known as VirtualBox headless configuration, because you’ll be managing guest machines without a monitor attached to the server.

We all know what VirtualBox is and how it can be used to install multiple guest machines on a single host computer. With VirtualBox software, a single host computer with more than enough resources, you can run Windows, Linux and other operating systems from that single host computer without needing separate computers for each operating system.

For more about VirtualBox, please read our previous post on it here.

Now, back to this post. We’re going to be installing VirtualBox software, phpVirtualBox, Apache2, and PHP in order for this to work.

This first thing we’re going to be doing is preparing the CentOS 7 server for the setup. To do that, lets install some development tools, including kernel-headers and others.

 

  • Preparing CentOS 7 Headless Server

To prepare the server, run the commands below to install some required development tools. Without these tools, VirtualBox will not be able to compile.

sudo yum groupinstall 'Development Tools' SDL kernel-devel kernel-headers dkms

 

  • Installing VirtualBox And its Extension Pack In CentOS 7

Now that these required tools are installed, let’s go and get VirtualBox repository file for CentOS. To do that, run the commands below.

cd /etc/yum.repos.d/ &&  sudo wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo

 

This will download the file but we also need the repository authentication key file. Run the commands below to download and install it.

sudo wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
sudo rpm --import oracle_vbox.asc

 

Next, run the commands below to install VirtualBox in CentOS 7

sudo yum update && sudo yum install VirtualBox-4.3

 

After installing VirtualBox, run the commands to download VirtualBox extension pack and install. The extension pack allows for VirtualBox to function properly.

cd /tmp/ &&  wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

Next, run the commands below to install the extension pack.

VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

VirtualBox and its extension pack are now installed and ready to use. Before connecting to it vie a web browser, we still need to configure other stuff.

To test if VBoxDrv installed correctly, run the commands below.

sudo /etc/init.d/vboxdrv setup

Restarted the server may also help. After restarted rerun the above commands.  Install EPEL repository might also help here. To learn how to install EPEL repository, check out this post.

 

  • Creating VirtualBox User account

Because VirtualBox and phpVirtualBox need a dedicated user account, let’s go and create it.  To do that, run the commands below to create a new user called richard, a password and add the account to VirtualBox user group.

sudo useradd richard
sudo password richard
sudo usermod -G vboxusers richard

 

  • Installing Apache2, PHP and Modules

To connect to VirtualBox headless server via a web browser, you must install Apache2 and PHP stuff. To do that run the commands below.

sudo yum install httpd php php-devel php-gd php-common php-soap

 

  • Installing phpVirtualBox

Now that VirtualBox installed, let’s go and install phpVirtualBox. To do that, run the commands below to download the latest version of the program.

cd /tmp/ && wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-1.zip

Then run the command below to unzip the downloaded file.

unzip phpvirtualbox-4.3-1.zip

 

Next, move the phpvirtualbox content to create a new root directory by running the commands below

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

Next, rename the sample configuration file to config.php.

sudo cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php

 

Then edit the config.php file and add VirtualBox user you created earlier.

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

 

Add the username and password for the user
[...]
var $username = 'richard';
var $password = 'my_password';
[...]

 

Save the file and close.

 

Next, create a new file called virtualbox in the /etc/default directory with this below info.

sudo vi /etc/default/virtualbox

Add this line

VBOXWEB_USER=richard

 

Save the file and close.

 

Finally, start VirtualBox webserver service by running the commands below.

/etc/init.d/vboxweb-service start

Restart Apahce2

systemctl restart httpd.service

 

Disable the firewall

sudo systemctl disable firewalld

Disable SELinux

sudo vi /etc/sysconfig/selinux

 

Change the line as shown below.
[...]
SELINUX=disabled
[...]

 

Restart your server and open your browser and connect to the server.

http://server_IP_address/phpvirtualbox

 

When prompted for username and password, enter

username = admin

password = admin

 

virtualbox headless setup for centos

 

Enjoy!