Skip to content

Instantly share code, notes, and snippets.

@daveamato
Created January 6, 2022 02:39
Show Gist options
  • Save daveamato/7554c275bf805066723712fa444f1f15 to your computer and use it in GitHub Desktop.
Save daveamato/7554c275bf805066723712fa444f1f15 to your computer and use it in GitHub Desktop.

VirtualBox Headless Ubuntu/Mint with phpVirtualBox

I had a lot of trouble setting this up, the guides out there don't seem complete. I used various guides and troubleshooting sites to get all of this figured out.

NOTE: My server's internal IP address is 10.10.10.100, you will need to substitute yours where appropriate.

Software Versions Used

  • Server Side
    • Linux Mint 18.1 Serena x86_64 with Kernel 4.4.0-139-generic
    • git 2.7.4
    • wget 1.17.1
    • gcc 5.4.0 20160609
    • GNU Make 4.1
    • dkms 2.2.0.3
    • VirtualBox 5.2.22
    • nginx 1.10.3
    • php 7.2
    • php-fpm 7.2
    • phpVirtualBox 5.2-1 (master branch)
  • Client Side
    • xQuartz 2.7.11
    • Homebrew 1.8.4
    • FreeRDP 1.0.2

OS Updates

You will need to run all of these commands with elevated privileges (sudo) or as root.

Update apt, update your distro, autoremove everything else.

apt update
apt dist-upgrade
apt autoremove

Install Requirements

Install git, wget, gcc, make, dkms, and the linux headers.

apt install git wget gcc make dkms linux-headers-$(uname -r)

VirtualBox

You will need to run all of these commands with elevated privileges (sudo) or as root.

Remove it All

apt remove virtualbox*
apt purge virtualbox*
apt autoremove

You'll need to remember the vbox user's password for later.

Get and Install VirtualBox

Get the latest stable release from the archive. As of today it is 5.2.22.

wget http://download.virtualbox.org/virtualbox/5.2.22/virtualbox-5.2_5.2.22-126460~Ubuntu~xenial_amd64.deb
dpkg -i virtualbox-5.2_5.2.22-126460~Ubuntu~xenial_amd64.deb

Install VirtualBox Extension Pack

Get the extension from the same release you downloaded VirtualBox.

wget http://download.virtualbox.org/virtualbox/5.2.22/Oracle_VM_VirtualBox_Extension_Pack-5.2.22-126460.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.22-126460.vbox-extpack

List installed packs.

VBoxManage list extpacks

Add User

useradd -m vbox -G vboxusers
passwd vbox

Setup The Configuration

In order to start vboxwebsrv, the file /etc/default/virtualbox must exist with correct settings.

touch /etc/default/virtualbox

Settings for this configuration file.

Setting Default Description
VBOXWEB_USER The user as which vboxwebsrv will run.
VBOXWEB_PASSWD The password of the user specified in VBOXWEB_USER.
VBOXWEB_HOST localhost The host to bind to.
VBOXWEB_PORT 18083 The port to bind to.
VBOXWEB_TIMEOUT 300 Session timeout in seconds; 0 = disable timeouts.
VBOXWEB_CHECK_INTERVAL 5 Frequency of timeout checks in seconds.
VBOXWEB_THREADS 100 Maximum number of worker threads to run in parallel.
VBOXWEB_KEEPALIVE 100 Maximum number of requests before a socket will be closed.
VBOXWEB_LOGFILE Name of file to write log to (no file). The vbox user must have rw access to this file.
INSTALL_DIR /usr/lib/virtualbox The location of the vboxwebsrv binary.

Basic /etc/default/virtualbox file:

VBOXWEB_USER=vbox
VBOXWEB_PASSWD=[the password you set when you created the vbox user]
VBOXWEB_HOST=10.10.10.100
VBOXWEB_PORT=18083
#VBOXWEB_TIMEOUT=
#VBOXWEB_CHECK_INTERVAL=
#VBOXWEB_THREADS=
#VBOXWEB_KEEPALIVE=
VBOXWEB_LOGFILE=/home/vbox/.config/VirtualBox/vboxweb-service.log
#INSTALL_DIR=

Run the vboxdrv setup.

/usr/lib/virtualbox/vboxdrv.sh setup

Check the status.

/usr/lib/virtualbox/vboxdrv.sh status

Should return:

VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded.

Test the vboxwebsrv.

su vbox -c '/usr/bin/vboxwebsrv -H localhost'

That should return something like this do CTRL-C to stop it.

Oracle VM VirtualBox web service Version 5.2.22
(C) 2007-2018 Oracle Corporation
All rights reserved.
VirtualBox web service 5.2.22 r126460 linux.amd64 (Nov  8 2018 20:32:53) release log
00:00:00.000130 main     Log opened 2018-11-26T23:11:00.306396000Z
00:00:00.000133 main     Build Type: release
00:00:00.000137 main     OS Product: Linux
00:00:00.000139 main     OS Release: 4.4.0-139-generic
00:00:00.000141 main     OS Version: #165-Ubuntu SMP Wed Oct 24 10:58:50 UTC 2018
00:00:00.000178 main     DMI Product Name: System Product Name
00:00:00.000189 main     DMI Product Version: System Version
00:00:00.000246 main     Host RAM: 15728MB (15.3GB) total, 12605MB (12.3GB) available
00:00:00.000252 main     Executable: /usr/lib/virtualbox/vboxwebsrv
00:00:00.000253 main     Process ID: 15213
00:00:00.000254 main     Package type: LINUX_64BITS_UBUNTU_16_04
00:00:00.002335 main     IPC socket path: /tmp/.vbox-vbox-ipc/ipcd
00:00:00.010981 SQPmp    Socket connection successful: host = localhost, port = 18083, master socket = 9

Enable & Start

systemctl enable vboxweb-service.service
systemctl start vboxweb-service.service
systemctl status vboxweb-service.service

modprobe vboxdrv
systemctl enable vboxdrv.service
systemctl start vboxdrv.service
systemctl status vboxdrv.service

NGINX / PHP Stack

You will need to run all of these commands with elevated privileges (sudo) or as root.

You can set this up under Apache, but I already had NGINX installed and didn't want to have two web servers.

This is largely figured out from Managing A Headless VirtualBox Installation With phpvirtualbox On nginx (Ubuntu 12.04).

Install PHP and nginx

Install nginx.

apt install nginx

Install php, php Fast Process Manager interpreter, php mysql, and php pear. This will install all of the other requirements.

apt install php-fpm php-pear php-soap

If you already have php installed you can get weird errors installing php-fpm, as I am no longer proficient with php, I couldn't guess why. I wound up doing a remove and purge then installing as above. Only do this if you have trouble, I added # to avoid copy/paste errors.

#apt remove php*
#apt purge php*
#apt autoremove

Start nginx.

systemctl start nginx.service
systemctl status nginx.service

Configure PHP FastCGI Process Manager

Edit the fpm php.ini file. I installed php7.2, yours may be different.

vi /etc/php/7.2/fpm/php.ini

Find:

;cgi.fix_pathinfo=1

Change to:

cgi.fix_pathinfo=0

Configure nginx

Find your nginx.conf file.

locate nginx.conf

Depending on your install it may be in several places, mine is at /etc/nginx.

You'll want to edit your sites-available/default.

vi /etc/nginx/sites-available/default

Look for the server configuration:

server {

In server find:

index index.html index.htm

Change to:

index index.php index.html index.htm

Also in the server configuration, add or uncomment two more locations:

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
           include snippets/fastcgi-php.conf;

           # With php7.0-cgi alone:
           #fastcgi_pass 127.0.0.1:9000;
           # With php7.0-fpm:
           fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
           deny all;
    }

NOTE: the fastcgi_pass unix:/run/php/php7.2-fpm.sock; line, be sure to change 7.2 to whatever gets installed on your server, mine was originally 7.0. You can do ls /run/php/ you should see a .pid and a .sock file with the version number.

Test the configuration.

nginx -t

Reload nginx.

systemctl reload nginx

Browse to your server.

http://10.10.10.100/

Test PHP

In your nginx docroot, usually /usr/share/nginx/html add a phpinfo.php file. The file should contain:

<?php
phpinfo();
?>

Then browse to it.

http://10.10.10.100/phpinfo.php

Install phpvirtualbox

These commands can be run as your regular user without elevated privileges. You may have to modify the privileges of your nginx docroot, depending on your install.

Go to your nginx docroot and clone phpvirtualbox.

cd /usr/share/nginx/html
git clone https://github.com/phpvirtualbox/phpvirtualbox.git

Checkout the master branch.

git checkout master

Setup your config.

mv config.php-example config.php
vi config.php

Find:

var $password = 'pass';

Change to whatever you set the vbox user's password to.

Find:

#var $consoleHost = '192.168.1.40';

Uncomment and change to the IP address of your server.

var $consoleHost = '10.10.10.100';

Find:

#var $vrdeaddress = '192.168.1.1';

Uncomment and change to 0.0.0.0.

var $vrdeaddress = '0.0.0.0';

Find:

#var $enableAdvancedConfig = true;

Uncomment and leave true.

var $enableAdvancedConfig = true;

Login to phpvirtualbox

Browse to:

http://10.10.10.100/phpvirtualbox

The default username and password are admin and admin.

Create a Virtual Machine

Setup a virtual machine as you normally would.

Setup Networking

Under Network

  • Select Adaptor 1
  • Attached to: Bridged Adaptor
  • Name: eno1 (this may be different)
  • Click OK

Setup Remote Display

Under Display

  • Select Remote Display.
  • Check Enable Server
  • Server Port: 9000-9100
  • Net Address: 10.10.10.100
  • Authentication Method: None
  • Authentication Timeout: 5000
  • Click OK

Start the VM.

You should see the VM start-up in the Preview window. Under Display you should see the Video Memory and Remote Desktop Server Port take note of the port, it is probably 9000.

Install an RDP Client

OSX

After experimenting with various RDP clients, I wound up using FreeRDP.

Open the xQuartz app.

In the xQuartz terminal enter, you'll need to change the IP to your server's IP address.

xfreerdp -a 32 10.10.10.100:9000

You can try different switches to change the speed and what not.

xfreerdp -a 16 -g 1024x768 --no-fastpath 10.10.10.100:9000

Linux

apt install freerdp-x11

Connect with:

xfreerdp -a 32 10.10.10.100:9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment