Difference between revisions of "PhpVirtualBox"

From ArchWiki
Jump to navigation Jump to search
(Web service)
m (PHP 7.2 style php.ini)
 
(32 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 
[[Category:Virtualization]]
 
[[Category:Virtualization]]
 
+
[[ja:PhpVirtualBox]]
 +
{{Related articles start}}
 +
{{Related|VirtualBox}}
 +
{{Related|:Category:Hypervisors}}
 +
{{Related|RemoteBox}}
 +
{{Related articles end}}
 
'''phpVirtualBox''' is an open source, AJAX implementation of the [[VirtualBox]] user interface written in [[PHP]]. As a modern web interface, it allows you to access and control remote VirtualBox instances. Much of its verbage and some of its code is based on the (inactive) vboxweb project. phpVirtualBox was designed to allow users to administer VirtualBox in a headless environment - mirroring the VirtualBox GUI through its web interface.  
 
'''phpVirtualBox''' is an open source, AJAX implementation of the [[VirtualBox]] user interface written in [[PHP]]. As a modern web interface, it allows you to access and control remote VirtualBox instances. Much of its verbage and some of its code is based on the (inactive) vboxweb project. phpVirtualBox was designed to allow users to administer VirtualBox in a headless environment - mirroring the VirtualBox GUI through its web interface.  
  
Line 7: Line 12:
  
 
=== VirtualBox web service ===
 
=== VirtualBox web service ===
To use the web console, you must install {{AUR|virtualbox-ext-oracle}} package from [[AUR]].
+
To use the web console, you must install the {{AUR|virtualbox-ext-oracle}} package.
  
 
=== VirtualBox web interface (phpvirtualbox) ===
 
=== VirtualBox web interface (phpvirtualbox) ===
[[pacman|Install]] {{Pkg|phpvirtualbox}} from [[Official Repositories]] on a php-capable web server of your choice ([[Apache]] is suitable choice).
+
[[Install]] the {{Pkg|phpvirtualbox}} package. You will also need a PHP-capable web server of your choice ([[Apache]] is suitable choice).
  
 
== Configuration ==
 
== Configuration ==
Line 16: Line 21:
  
 
=== Web service ===
 
=== Web service ===
In virtual machine settings, enable the remote desktop access and specify a port different with other virtual machines.
+
In the virtual machine settings, enable the remote desktop access and specify a port different with other virtual machines.
  
 
Every time you need to make machine remotely available execute something like this:
 
Every time you need to make machine remotely available execute something like this:
Line 22: Line 27:
 
  vboxwebsrv -b --logfile '''path to log file''' --pidfile /run/vbox/vboxwebsrv.pid --host 127.0.0.1
 
  vboxwebsrv -b --logfile '''path to log file''' --pidfile /run/vbox/vboxwebsrv.pid --host 127.0.0.1
  
As user whom account you want service to be running from ({{Ic|--host}} option is not necessary if you enabled association with '''localhost''' in the {{Ic|/etc/host.conf}}).
+
As user whose account you want the service to be running from ({{Ic|--host}} option is not necessary if you enabled association with '''localhost''' in the {{Ic|/etc/host.conf}}).
  
 
{{Note|This user must be in group '''vboxusers'''!}}
 
{{Note|This user must be in group '''vboxusers'''!}}
  
{{Pkg|virtualbox}} is available in community and it's contains the '''vboxweb.service''' for [[systemd]].  
+
{{Pkg|virtualbox}} is available in the community and it contains the {{Ic|vboxweb.service}} for [[systemd]].  
  
For start '''vboxweb''' from custom user you must:  
+
To start {{Ic|vboxweb}} from '''non-root user''' you must:  
  
1. Create or add a user in the group '''vboxusers''' (for example, '''vbox''')
+
1. Create or add a user in the group {{Ic|vboxusers}} (for example, {{Ic|vbox}})
  
2. Create your custom vboxweb_mod service file by copy '''/usr/lib/systemd/system/vboxweb.service''' to '''/etc/systemd/system/vboxweb_mod.service'''
+
2. Create your custom {{Ic|vboxweb_mod.service}} file by copying {{Ic|/usr/lib/systemd/system/vboxweb.service}} to {{Ic|/etc/systemd/system/vboxweb_mod.service}}
  
3. Modify '''/etc/systemd/system/vboxweb_mod.service''' like this:
+
3. Modify {{Ic|/etc/systemd/system/vboxweb_mod.service}} like this:
 
  <nowiki> [Unit]
 
  <nowiki> [Unit]
 
  Description=VirtualBox Web Service
 
  Description=VirtualBox Web Service
Line 49: Line 54:
 
  WantedBy=multi-user.target</nowiki>
 
  WantedBy=multi-user.target</nowiki>
  
4. Create tmpfile rule for your '''vboxweb_mod.service''':
+
4. Create tmpfile rule for your {{Ic|vboxweb_mod.service}}
  # echo "D /run/vboxweb 0755 vbox vboxusers" > /usr/lib/tmpfiles.d/vboxweb_mod.conf
+
  # echo "d /run/vboxweb 0755 vbox vboxusers" > /etc/tmpfiles.d/vboxweb_mod.conf
  
5. Create manually '''/run/vboxweb''' directory for first start '''vboxweb_mod.service'''
+
5. Create manually {{Ic|/run/vboxweb}} directory for first start {{Ic|vboxweb_mod.service}}
 
  # mkdir /run/vboxweb
 
  # mkdir /run/vboxweb
 
  # chown vbox:vboxusers /run/vboxweb
 
  # chown vbox:vboxusers /run/vboxweb
 
  # chmod 755 /run/vboxweb
 
  # chmod 755 /run/vboxweb
or just reboot your system automatically create
+
or just reboot your system for automatically create.
  
6. Start '''vboxweb_mod'''
+
6. [[Start]]/[[enable]] {{ic|vboxweb_mod.service}}
# systemctl start vboxweb_mod
 
and enable it if nessesary
 
# systemctl enable vboxweb_mod
 
  
 
=== Web interface ===
 
=== Web interface ===
Edit {{Ic|/etc/php/php.ini}}, make sure the following lines are uncommented.
+
Edit {{Ic|/etc/php/php.ini}}, uncomment the following line:
 +
extension=soap
  
extension=json.so
+
Edit the example configuration file {{Ic|/usr/share/webapps/phpvirtualbox/config.php-example}} appropriately (it is well-commented and does not need explanations). Copy that file into {{Ic|/etc/webapps/phpvirtualbox/config.php}} and symlink to {{Ic|/usr/share/webapps/phpvirtualbox/config.php}}.
extension=soap.so
 
  
Don't forget to restart the webserver like this (example for Apache):
+
Then, edit {{Ic|/etc/php/php.ini}}, find {{Ic|open_basedir}} and append the configuration path {{Ic|/etc/webapps/}} at the end. It will look like the follows:
  
{{Ic|rc.d restart httpd}}
+
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/
  
Edit the example configuration file {{Ic|/usr/share/webapps/phpvirtualbox/config.php-example}} appropriately (it is well-commented and does not need explanations). <strike>Copy that file into /etc/webapps/phpvirtualbox/config.php, /usr/share/webapps/phpvirtualbox/config.php and /usr/share/webapps/phpvirtualbox/lib/config.php.</strike> Do not copy it over /usr/share/webapps/phpvirtualbox/config.php (these are the same file thanks to symlinks) and '''never overwrite''' /usr/share/webapps/phpvirtualbox/lib/config.php (this file should not be changed).
+
If you are running Apache as webserver, you can copy {{Ic|/etc/webapps/phpvirtualbox/apache.example.conf}} into {{Ic|/etc/httpd/conf/extra/phpvirtualbox.conf}}. If you are running Apache 2.4, due to [http://httpd.apache.org/docs/2.4/upgrading.html#run-time the syntax of ACL changes], edit that file to replace the follows
  
If you are running Apache as webserver, you can copy {{Ic|/etc/webapps/phpvirtualbox/apache.example.conf}} into {{Ic|/etc/httpd/conf/extra/phpvirtualbox.conf}}, and then add following line into {{Ic|/etc/httpd/conf/httpd.conf}}:
+
Order allow,deny
 +
Allow from all
 +
 
 +
to:
 +
 
 +
Require all granted
 +
 
 +
Next, add following line into {{Ic|/etc/httpd/conf/httpd.conf}}:
  
 
  Include conf/extra/phpvirtualbox.conf
 
  Include conf/extra/phpvirtualbox.conf
Line 82: Line 91:
  
 
  deny from all
 
  deny from all
 +
 +
Do not forget to restart the webserver (e.g. for Apache, [[restart]] {{ic|httpd.service}}).
  
 
== Running ==
 
== Running ==
Line 99: Line 110:
  
 
== External Resources ==
 
== External Resources ==
* [http://code.google.com/p/phpvirtualbox/ PHPVirtualBox Home Page]
+
* [http://sourceforge.net/projects/phpvirtualbox/ PHPVirtualBox Home Page]
 
* [http://www.torrent-invites.com/software/101718-manage-your-virtualbox-vms-via-web-phpvirtualbox.html Manage your VirtualBox VMs via the web with phpVirtualBox]
 
* [http://www.torrent-invites.com/software/101718-manage-your-virtualbox-vms-via-web-phpvirtualbox.html Manage your VirtualBox VMs via the web with phpVirtualBox]
 +
* [https://bbs.archlinux.org/viewtopic.php?id=147175 systemd vboxweb.service mod when needing to start as non-root user]

Latest revision as of 11:02, 18 March 2018

phpVirtualBox is an open source, AJAX implementation of the VirtualBox user interface written in PHP. As a modern web interface, it allows you to access and control remote VirtualBox instances. Much of its verbage and some of its code is based on the (inactive) vboxweb project. phpVirtualBox was designed to allow users to administer VirtualBox in a headless environment - mirroring the VirtualBox GUI through its web interface.

Installation

To remotely control virtual machine you need two components: VirtualBox web service, running in the same OS with virtual machine, and web interface, written in PHP and therefore dependent on PHP-capable web server. Communication between them, based on SOAP protocol is currently unencrypted, so it is recommended to install both on the same machine if you do not want your username and password to be send via network as clear text.

VirtualBox web service

To use the web console, you must install the virtualbox-ext-oracleAUR package.

VirtualBox web interface (phpvirtualbox)

Install the phpvirtualbox package. You will also need a PHP-capable web server of your choice (Apache is suitable choice).

Configuration

From here on out, it is assumed that you have a web server (with root at /srv/http) and php functioning properly.

Web service

In the virtual machine settings, enable the remote desktop access and specify a port different with other virtual machines.

Every time you need to make machine remotely available execute something like this:

vboxwebsrv -b --logfile path to log file --pidfile /run/vbox/vboxwebsrv.pid --host 127.0.0.1

As user whose account you want the service to be running from (--host option is not necessary if you enabled association with localhost in the /etc/host.conf).

Note: This user must be in group vboxusers!

virtualbox is available in the community and it contains the vboxweb.service for systemd.

To start vboxweb from non-root user you must:

1. Create or add a user in the group vboxusers (for example, vbox)

2. Create your custom vboxweb_mod.service file by copying /usr/lib/systemd/system/vboxweb.service to /etc/systemd/system/vboxweb_mod.service

3. Modify /etc/systemd/system/vboxweb_mod.service like this:

 [Unit]
 Description=VirtualBox Web Service
 After=network.target

 [Service]
 Type=forking
 PIDFile=/run/vboxweb/vboxweb.pid
 ExecStart=/usr/bin/vboxwebsrv --pidfile /run/vboxweb/vboxweb.pid  --background
 User=vbox
 Group=vboxusers

 [Install]
 WantedBy=multi-user.target

4. Create tmpfile rule for your vboxweb_mod.service

# echo "d /run/vboxweb 0755 vbox vboxusers" > /etc/tmpfiles.d/vboxweb_mod.conf

5. Create manually /run/vboxweb directory for first start vboxweb_mod.service

# mkdir /run/vboxweb
# chown vbox:vboxusers /run/vboxweb
# chmod 755 /run/vboxweb

or just reboot your system for automatically create.

6. Start/enable vboxweb_mod.service

Web interface

Edit /etc/php/php.ini, uncomment the following line:

extension=soap

Edit the example configuration file /usr/share/webapps/phpvirtualbox/config.php-example appropriately (it is well-commented and does not need explanations). Copy that file into /etc/webapps/phpvirtualbox/config.php and symlink to /usr/share/webapps/phpvirtualbox/config.php.

Then, edit /etc/php/php.ini, find open_basedir and append the configuration path /etc/webapps/ at the end. It will look like the follows:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

If you are running Apache as webserver, you can copy /etc/webapps/phpvirtualbox/apache.example.conf into /etc/httpd/conf/extra/phpvirtualbox.conf. If you are running Apache 2.4, due to the syntax of ACL changes, edit that file to replace the follows

Order allow,deny
Allow from all

to:

Require all granted

Next, add following line into /etc/httpd/conf/httpd.conf:

Include conf/extra/phpvirtualbox.conf

Edit /etc/webapps/phpvirtualbox/.htaccess and remove the following line.

deny from all

Do not forget to restart the webserver (e.g. for Apache, restart httpd.service).

Running

If everything works fine, visit http://YourVboxWebInterfaceHost/phpvirtualbox and it should show a login box. The initial username and password are both "admin", after login change them from the web interface (File -> change password). If you set $noAuth=true in the web interface config.php, you should immediately see the phpvirtualbox web interface.

Debugging

If you encounter a login problem, and you have upgraded virtualbox from 3.2.x to 4.0.x, you should run the following command to update you websrvauthlibrary in you virtualbox configuration file which has been changed from VRDPAuth.so to VBOXAuth.so.

VBoxManage setproperty vrdeauthlibrary default
VBoxManage setproperty websrvauthlibrary default 

If you are still unable to login into the interface, you can try to disable webauth by

VBoxManage setproperty websrvauthlibrary null

on virtualization server and set username and password to empty strings and set $noAuth=true in /etc/webapps/phpvirtualbox/config.php on web server. By doing this, you should immediatelly access the web interface without login process. And then, maybe you can try some apache access control.

External Resources