Home Linux DistributionsDebian How to Install Oracle VirtualBox On Ubuntu 18.04.2 LTS Headless Server
Install Oracle VirtualBox On Ubuntu 18.04 LTS server

How to Install Oracle VirtualBox On Ubuntu 18.04.2 LTS Headless Server

By sk

This step by step tutorial explains how to install Oracle VirtualBox on Ubuntu 18.04.2 LTS headless server and how to manage the VirtualBox headless instances using phpVirtualBox, a web-based front-end tool for VirtualBox. The steps described below might also work on Debian and other Ubuntu derivatives such as Linux Mint. Let us get started.


Before installing Oracle VirtualBox, we need to do the following prerequisites in our Ubuntu 18.04.2 LTS server.

First of all, make sure you have enabled universe and multiverse repositories if they are not enabled already. These repositories are required to install some dependencies while installing Virtualbox.

$ sudo add-apt-repository universe
$ sudo add-apt-repository multiverse

And then, update the Ubuntu server by running the following commands one by one.

$ sudo apt update
$ sudo apt upgrade
$ sudo apt dist-upgrade

Next, install the following necessary packages:

$ sudo apt install build-essential dkms unzip wget

After installing all updates and necessary prerequisites, restart the Ubuntu server.

$ sudo reboot

Install Oracle VirtualBox on Ubuntu 18.04 LTS server

Add Oracle VirtualBox official repository. To do so, edit /etc/apt/sources.list file:

$ sudo nano /etc/apt/sources.list

Add the following lines.

Here, I will be using Ubuntu 18.04.2 LTS, so I have added the following repository.

deb http://download.virtualbox.org/virtualbox/debian bionic contrib
Add Oracle VirtualBox official repository

Add Oracle VirtualBox official repository

Replace the word 'bionic' with your Ubuntu distribution's code name, such as 'xenial', 'vivid', 'utopic', 'trusty', 'raring', 'quantal', 'precise', 'lucid', 'jessie', 'wheezy', or 'squeeze'.

Then, run the following command to add the Oracle public key:

$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -

For VirtualBox older versions, add the following key:

$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Next, update the software sources using command:

$ sudo apt update

Finally, install latest Oracle VirtualBox latest version using command:

$ sudo apt install virtualbox-5.2

Adding users to VirtualBox group

We need to create and add our system user to the vboxusers group. You can either create a separate user and assign it to vboxusers group or use the existing user. I don't want to create a new user, so I added my existing user to this group. Please note that if you use a separate user for virtualbox, you must log out and log in to that particular user and do the rest of the steps.

I am going to use my username named sk, so, I ran the following command to add it to the vboxusers group.

$ sudo usermod -aG vboxusers sk

Now, run the following command to check if virtualbox kernel modules are loaded or not.

$ sudo systemctl status vboxdrv

As you can see in the above screenshot, the vboxdrv module is loaded and running!

For older Ubuntu versions, run:

$ sudo /etc/init.d/vboxdrv status

If the virtualbox module doesn't start, run the following command to start it.

$ sudo /etc/init.d/vboxdrv setup

Great! We have successfully installed VirtualBox and started virtualbox module. Now, let us go ahead and  install Oracle VirtualBox extension pack.

Install VirtualBox Extension pack

The VirtualBox Extension pack provides the following functionalities to the VirtualBox guests.

  • The virtual USB 2.0 (EHCI) device
  • VirtualBox Remote Desktop Protocol (VRDP) support
  • Host webcam passthrough
  • Intel PXE boot ROM
  • Experimental support for PCI passthrough on Linux hosts

Download the latest Extension pack for VirtualBox 5.2.x from here.

$ wget https://download.virtualbox.org/virtualbox/5.2.30/Oracle_VM_VirtualBox_Extension_Pack-5.2.30.vbox-extpack

Install Extension pack using command:

$ sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.30.vbox-extpack

Congratulations! We have successfully installed Oracle VirtualBox with extension pack in Ubuntu 18.04 LTS server. It is time to deploy virtual machines. Refer the virtualbox official guide to start creating and managing virtual machines in command line.

Not everyone is command line expert. Some of you might want to create and use virtual machines graphically. No worries! Here is where phpVirtualBox comes in handy!!

About phpVirtualBox

PhpVirtualBox is a free, web-based front-end to Oracle VirtualBox. It is written using PHP language. Using phpVirtualBox, we can easily create, delete, manage and administer virtual machines via a web browser from any remote system on the network.

Install phpVirtualBox in Ubuntu 18.04 LTS

Since it is a web-based tool, we need to install Apache web server, PHP and some php modules.

To do so, run:

$ sudo apt install apache2 php php-mysql libapache2-mod-php php-soap php-xml

Then, Download the phpVirtualBox 5.2.x version from the releases page. Please note that we have installed VirtualBox 5.2, so we must install phpVirtualBox version 5.2 as well.

To download it, run:

$ wget https://github.com/phpvirtualbox/phpvirtualbox/archive/5.2-1.zip

Extract the downloaded archive with command:

$ unzip 5.2-1.zip

This command will extract the contents of 5.2.1.zip file into a folder named "phpvirtualbox-5.2-1". Now, copy or move the contents of this folder to your apache web server root folder.

$ sudo mv phpvirtualbox-5.2-1/ /var/www/html/phpvirtualbox

Assign the proper permissions to the phpvirtualbox folder.

$ sudo chmod 777 /var/www/html/phpvirtualbox/

Next, let us configure phpVirtualBox.

Copy the sample config file as shown below.

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

Edit phpVirtualBox config.php file:

$ sudo nano /var/www/html/phpvirtualbox/config.php

Find the following lines and replace the username and password with your system user (The same username that we used in "Adding users to VirtualBox group" section).

In my case, my Ubuntu system username is sk, and its password is ubuntu.

var $username = 'sk';
var $password = 'ubuntu';

Save and close the file.

Next, create a new file called /etc/default/virtualbox:

$ sudo nano /etc/default/virtualbox

Add the following line. Replace 'sk' with your own username.


Finally, Reboot your system or simply restart the following services to complete the configuration.

$ sudo systemctl restart vboxweb-service
$ sudo systemctl restart vboxdrv
$ sudo systemctl restart apache2

Adjust firewall to allow Apache web server

By default, the apache web browser can't be accessed from remote systems if you have enabled the UFW firewall in Ubuntu 18.04 LTS. You must allow the http and https traffic via UFW by following the below steps.

First, let us view which applications have installed a profile using command:

$ sudo ufw app list
Available applications:
Apache Full
Apache Secure

As you can see, Apache and OpenSSH applications have installed UFW profiles.

If you look into the "Apache Full" profile, you will see that it enables traffic to the ports 80 and 443:

$ sudo ufw app info "Apache Full"
Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web


Now, run the following command to allow incoming HTTP and HTTPS traffic for this profile:

$ sudo ufw allow in "Apache Full"
Rules updated
Rules updated (v6)

If you don't want to allow https traffic, but only http (80) traffic, run:

$ sudo ufw app info "Apache"

Access phpVirtualBox Web console

Now, go to any remote system that has graphical web browser.

In the address bar, type: http://IP-address-of-virtualbox-headless-server/phpvirtualbox.

In my case, I navigated to this link -

You should see the following screen. Enter the phpVirtualBox administrative user credentials.

The default username and phpVirtualBox is admin/admin.

phpvirtualbox login page

phpvirtualbox login page

Congratulations! You will now be greeted with phpVirtualBox dashboard.

phpvirtualbox dashboard

phpvirtualbox dashboard

Now, start creating your VMs and manage them from phpvirtualbox dashboard as the way you do in Virtualbox standalone application. As I mentioned earlier, You can access the phpVirtualBox from any system in the same network. All you need is a web browser and the username and password of phpVirtualBox.

I tested this guide on Ubuntu 18.04.2 LTS server and it worked just fine as described. However, If you ran into any problem, do check the comment section below. Some of our readers have provided a few tips to get this working on Ubuntu.

A note for installing 64-bit guest OS

If you haven't enabled virtualization support in the BIOS of host system (not the guest), phpVirtualBox allows you to create 32-bit guests only. To install 64-bit guest systems, you must enable virtualization in your host system's BIOS. Look for an option that is something like "virtualization" or "hypervisor" in your bios and make sure it is enabled.

Some of you might think why on earth anyone would use phpvirtualbox while we already have a better solution - KVM. This tutorial is mainly for those who get used to Oracle virtualbox. If you prefer KVM over Virtualbox, refer the following guide.

And, that's all. Hope this helps. If you find this guide useful, please share it on your social, professional networks and support us.

Reference links:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like


Gianni Franceschinis August 9, 2017 - 6:26 am

This is a great guide.
Thanks so much!!!

Daryl Lee September 13, 2017 - 11:50 pm

Nice work. But when I browse to phpvirtualbox and log in, I get a failure to connect to “”. Any idea what that’s all about? The userid/pwd is correct

Vinicius Zanellato October 26, 2017 - 7:00 pm

For me too. Did you fixed?

Bart Cockheyt November 19, 2017 - 2:47 pm

Change to your actual servers ip adress on line 16 in sudo nano /var/www/html/phpvirtualbox/config.php
Then restart the services.

Peter April 18, 2019 - 12:20 am

Had the same problem here, running VBox 5.2.28 and phpvirtualbox 5.2.1

Changing to the actual IP did not change an thing. Why should it? They are both pointing to the same machine.

The command vboxwebsrv -H told me that VBox could not access the folder .config in my home. Checking this showed that both .config and .local were owned by root, possibly to an unnecessary sudo while installing.

chown fixed the whole thing 🙂

Chuck Razalas November 24, 2017 - 8:25 am

Great tutorial but like every other time I have tried I get the same issue about failure to connect to “” and I have changed the IP and I have changed the usernames and I have made sure to allow the port 18083 and no matter what I do it NEVER works. I have tried on CentOS 7 and now Ubuntu 16.04 LTS and same issue every single time no matter what tutorial I try. I followed this guide to a “T” and same as all the rest. Why is this so complicated and why does it NEVER work?

Chuck Razalas November 24, 2017 - 4:06 pm

Ok never mind. I finally got it to work. I didn’t change the this time and most importantly, I made sure I did all the steps with the correct User this time. So overall your tutorial was 100% dead on I just didn’t follow the users clause so that was on me. Thanks so much for providing a tutorial that was easy to follow and that actually worked for me.

Chuck Razalas November 27, 2017 - 12:49 am

Quick question SK. Ok so I have everything working perfectly and I did end up having to change the IP to my actual server IP after all. I can login to the PHP Virtual box login and I can see the VM I created and it’s running and all is well except one problem. I can only see it in the console screen and I cannot access the VM from a web browser. My VM is Univention Corporate Server and again I can see it running in the Console but I need to access the Univention Portal from a web browser and not the Virtual Box console. How can I see a VM I create from the outside? No matter what I do I just can’t access it. Thanks in advance.

SK November 28, 2017 - 12:19 pm

If both systems (VM and the host) are in the same network, you can access it from the web browser. Check the network settings of your VM and make sure you have selected the “Bridged network” option. https://uploads.disquscdn.com/images/c7dfe4ff585e8150a3dd24b0bcf1fd317cc89dd4af5d06cca3f8b74e4689a4c3.png

Chuck Razalas November 28, 2017 - 11:27 pm

One problem with that SK. My hosting company 1&1 doesn’t allow Bridging, go figure right? So what I have tried is using adapter 1 as Host Only and adapter 2 as Nat but no luck. I even tried port forwarding from my server ip to and still no luck. Also tried adding the following command in IP Tables: iptables -t nat -A PREROUTING -p tcp -d my.server.ip –dport 80 -j DNAT –to-destination and also no luck. I have tried with Ubuntu 16.04 LTS and now trying again with CentOS 7 as the base. The VirtualBox install process goes off without a hitch. I am then trying to install Univention Corporate Server as a VM in VirtualBox and it installs but always says it could not set a default route and makes me manually enter my netwwork details. I input my server ip, then the submask comes up and it’s different than what the host server submask actually is. I change it to what it is on the actual host server, then when Gateway comes up I try what my hosting company says the host Gateway IP is and always get an error saying it’s unreachable. I then try again with the auto defaults that pop up and again nothing. I’m so frustrated with this at this point. Any other ideas?

SK November 29, 2017 - 11:44 am

Hello Chuck, enabling bridge network on VM has nothing to do with hosting provider as far as I know. Because, you’re enabling it on your VM, not in the host system. The VM (The univention server) should be reachable in-order to access it from a remote system. I am not a expert in networking. I don’t know how to do it. My apologies.

Lucien Bunel August 30, 2018 - 2:41 pm

Hello !
I just switched from Ubuntu server 16.04 LTS to Ubuntu server 18.04 LTS
and I lost my PhPvirtualbox … so I did your tutorial like I did for 16.04, but the Apache2 does not want to start?
root @ proliant: ~ # journalctl -xe
– Support: http://www.ubuntu.com/support

– The vboxdrv.service unit (unit) has completed its startup, with the RESU result
Aug 30 10:58:40 proliant systemd [1]: Starting The Apache HTTP Server …
– Subject: The unit (unit) apache2.service started to start
– Defined-By: systemd
– Support: http://www.ubuntu.com/support

– The unit (unit) apache2.service started to start.
Aug 30 10:58:40 proliant apachectl [5348]: (98) Address already in use: AH00072:
Aug 30 10:58:40 proliant apachectl [5348]: (98) Address already in use: AH00072:
Aug 30 10:58:40 proliant apachectl [5348]: no listening sockets available, shutt
Aug 30 10:58:40 proliant apachectl [5348]: AH00015: Unable to open logs
Aug 30 10:58:40 proliant apachectl [5348]: Action ‘start’ failed.
Aug 30 10:58:40 proliant apachectl [5348]: The Apache error log
Aug 30 10:58:40 proliant systemd [1]: apache2.service: Control process exited, c
Aug 30 10:58:40 proliant systemd [1]: apache2.service: Failed with result ‘exit-
Aug 30 10:58:40 proliant systemd [1]: Failed to start The Apache HTTP Server.
– Subject: The unit (unit) apache2.service failed
– Defined-By: systemd
– Support: http://www.ubuntu.com/support

– The unit (unit) apache2.service failed, with result RESULT.
proliant root @: ~ #
do you have an idea ?
Thanks part ahead

Lucien Bunel August 30, 2018 - 8:31 pm

I reinstall Apache2 🙂 now I have blue screen with error >>
An unknown PHP error occurred. This is most likely a syntax error in config.php in phpVirtualBox’s folder. The most common errors are a missing item or a missing item in a configuration item that has been entered (e.g. location, username, or password).

Depending on your PHP configuration, navigating directly to config.php in your web browser may display the PHP error message.

If this is not the case, please raise the issue at http://sourceforge.net/p/phpvirtualbox/discussion/help/

I put the user and password pass but not arrive?

Lucien Bunel September 1, 2018 - 3:31 am

hello it works now after installing
soap extension

Tanvir October 17, 2018 - 1:11 pm

Thank you .
it worked fine

Gary Cuppett November 6, 2018 - 3:34 am

Are these instructions complete and working for Ubuntu 18.04.1 LTS ???

sk November 6, 2018 - 11:05 am

Yes it works.

John Anderson November 8, 2018 - 9:57 am

Just as a note, I was not able to install until I enabled the Canonical universe libraries too.

Shaly November 8, 2018 - 7:32 pm

It fails to install virtualbox package expecting few libraries as dependencies – and those libraries are not available as packages from the default repo’s from what I’m seeing. Is that die to the canonical universe libraries?

Jens G November 19, 2018 - 8:36 am

Thanks for this. But I get:

The following packages have unmet dependencies:
virtualbox-5.2 : Depends: libqt5x11extras5 (>= 5.6.0) but it is not installable
Recommends: libsdl-ttf2.0-0 but it is not installable
Recommends: pdf-viewer

When running sudo apt install virtualbox-5.2

Any ideas?

Jens G November 19, 2018 - 1:58 pm

After see this: https://askubuntu.com/questions/1081243/why-do-i-need-to-enable-universe-repo-in-18-04-isnt-it-default-enabled

and running: sudo add-apt-repository universe

I was able to proceed

Antonio November 24, 2018 - 8:37 pm

Awesome thanks! I was stuck there too!

Robin van Ruitenbeek November 29, 2018 - 8:14 pm

Hmm.. everything seems to be working but when i try to login it says:

Exception Object
[message:protected] => DTD are not supported by SOAP (
[string:Exception:private] =>
[code:protected] => 64
[file:protected] => /var/www/html/phpvirtualbox/endpoints/api.php
[line:protected] => 134
[trace:Exception:private] => Array

[previous:Exception:private] =>

greg December 7, 2018 - 7:23 am

i make it work try this
vboxwebsrv -H

Toby January 30, 2019 - 9:05 pm

Your instructions are on the mark! Much gratitude!

germanguy32 February 12, 2019 - 4:27 am

Oracle Homepage looses against you!
after a short periode reading on your site, it can be seen: there’s a checker on work! good to know…
Thx man.
..it can be soo easy—

Ben February 22, 2019 - 7:21 am

Brilliant guide, thankyou!

Just a heads up on Ubuntu server 18.04 I couldn’t for the life of me get virtualbox to run until I disabled secureboot, followed these instructions to do it : https://wiki.ubuntu.com/UEFI/SecureBoot/DKMS

sk February 22, 2019 - 11:43 am

Thank you. Glad it worked for you.

jfgvtyfyu February 22, 2019 - 11:43 pm

Exception Object
[message:protected] => Could not connect to host (
[string:Exception:private] =>
[code:protected] => 64
[file:protected] => /var/www/html/phpvirtualbox/endpoints/api.php
[line:protected] => 134
[trace:Exception:private] => Array

[previous:Exception:private] =>

● vboxweb-service.service
Loaded: loaded (/usr/lib/virtualbox/vboxweb-service.sh; enabled; vendor prese
Active: active (exited) since Fri 2019-02-22 18:10:56 UTC; 1min 17s ago
Process: 12659 ExecStop=/usr/lib/virtualbox/vboxweb-service.sh stop (code=exit
Process: 12667 ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start (code=ex

févr. 22 18:10:56 ns3311288 systemd[1]: Starting vboxweb-service.service…
févr. 22 18:10:56 ns3311288 systemd[1]: Started vboxweb-service.service.
lines 1-8/8 (END)…skipping…
● vboxweb-service.service
Loaded: loaded (/usr/lib/virtualbox/vboxweb-service.sh; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2019-02-22 18:10:56 UTC; 1min 17s ago
Process: 12659 ExecStop=/usr/lib/virtualbox/vboxweb-service.sh stop (code=exited, status=0/SUCCESS)
Process: 12667 ExecStart=/usr/lib/virtualbox/vboxweb-service.sh start (code=exited, status=0/SUCCESS)

févr. 22 18:10:56 ns3311288 systemd[1]: Starting vboxweb-service.service…
févr. 22 18:10:56 ns3311288 systemd[1]: Started vboxweb-service.service.

service starting work login

user admin
password admin

not work please solve

jfgvtyfyu February 22, 2019 - 11:46 pm

ok service not corect start

juste restart use full command line

/usr/lib/virtualbox/vboxweb-service.sh stop

/usr/lib/virtualbox/vboxweb-service.sh start

and working please update your tutorial

for add this command

YADIR HERNANDEZ BATISTA March 14, 2019 - 10:53 pm

Based on you tutorial I automated the installation and config, also updated the phpvirtualbox to latest and VirtualBox too. Anyone can use this script in terminal copy and execute this –> bash <(curl -sS https://raw.githubusercontent.com/adryo/scripts/develop/setup/macos-vm.sh) installVBoxClient –logon-password 'The current user's password'.

The –logon-password is to install and configure the vbox 6.0 and phpvirtualbox 5.2-1 unattended.

After installation remember to change the admin/admin credentials.

Give it a try.

Eric Marcus March 27, 2019 - 10:59 pm

Hi, sorry, I didn’t understand the last steps:

If you want to allow https traffic, but only http (80) traffic, run:

$ sudo ufw app info “Apache”

??? This is just a repeat of a previous step for ufw info, it doesn’t modify the ufw rules?

Otherwise, thanks!

Roberto July 7, 2019 - 12:32 am

Thanks for this excellent tutorial!!

Everything works fine, except the phpvirtualbox’s console.

Clicking on “Console” button, the error message “The Adobe Flash plugin is not installed” shows up.

I’m using Google Chrome browser (ver. 75.0 last update on July 5, 2019).

Thanks for any help.

Best regards

sk July 7, 2019 - 9:13 pm

Install Adobe flash plugin in the system that you use to access phpvirtualbox and try.

TheWeasel September 17, 2019 - 9:08 pm

Having trouble accessing the VMs using rdp. I have tried to create my own RDP connection, and I have clicked on the port number in phpvirtualbox to get a rdp config downloaded. I have updated the IP address to the servers real address, but still can not get a connection to run. I just get the following error.
1. Remote access to the server is not enabled
2. The Remote Computer is turned off
3. The remote computer is not available on the network.

Hugo November 26, 2019 - 12:50 pm

Excellent guide.
Just completed installation of Ubuntu server on a ProLiant 380 box previously running VMware on which I installed VirtualBox.

The instructions made this task a piece of cake.

Thank you very much.

george February 18, 2020 - 12:12 am

i would like to set this up on a ubuntu 18.04 LTS server headless thats running iredmail with lemp. how would these instructions differ if this is even possible? thanks Looks like a great tutorial.

Arman February 27, 2020 - 5:11 pm

Hello! I want to thank You for this article. It is great, thank You very much I have already install my vm with phpvirtualbox. Thanks a lot.

sk February 27, 2020 - 6:48 pm

Glad I could help.

Martin March 1, 2020 - 10:43 pm

Excellent tutorial – however for me it doesn’t work 🙁
When I try to start phpVirtualBox I get a message box saying
“An unknown PHP error occurred. This is most likely a syntax error in config.php in phpVirtualBox’s folder. The most common errors are an unclosed quote or a missing semicolon in a configuration item that has been entered (e.g. location, username, or password).

Depending on your PHP configuration, navigating directly to config.php in your web browser may display the PHP error message.

If find that this is not the case, or have no idea what this error message means, please raise the issue at http://sourceforge.net/p/phpvirtualbox/discussion/help/

with no help or indication of what to do.
I have changed all the ip addresses I can find from to my host ip but that doesn’t work.

I’m running on ubuntu server 18.04

Any suggestions on finding and fixing the error message?


Jay May 24, 2020 - 3:31 am

Thank you,

I am new to Linux and command lines but its fully working

With love

Peter June 28, 2020 - 3:54 am

If you have set authentication is phpvirtualbox config.php, make sure to do:
passwd vbox
–> password
and set:
/* Username / Password for system user that runs VirtualBox */
var $username = ‘vbox’;
var $password = ‘password’;

Lucien Bunel September 23, 2020 - 3:34 pm

hello, someone has the problem with the rdp connection (console) “Reason for disconnection: E: TCP: SECURITY_ERROR Error # 2048”
I can not open to make the instalation of any vms?

sk September 23, 2020 - 6:46 pm Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More