I have to say, I have been bursting with some excitement to recently discover this gem. phpVirtualBox is going to make a great addition to my server by allowing me to create and manage VirtualBox VM’s direct from my web browser. So just a small guide, sticking with the theme, on getting phpVirtualBox installed and running on CentOS 7.x.

Install required packages

Install Apache Web Server

# sudo yum install httpd

Start Apache and ensure it starts automatically on boot.

# sudo systemctl start httpd
# sudo systemctl enable httpd

Finally, add an exception in the firewall so that you can access Apache over HTTP and HTTPS.

# sudo firewall-cmd --zone=public --add-service=http
# sudo firewall-cmd --zone=public --permanent --add-service=http
# sudo firewall-cmd --zone=public --add-service=https
# sudo firewall-cmd --zone=public --permanent --add-service=https

Test that Apache is running and accessible by opening a browser and navigating to http://server_ip_address.

Install PHP

# sudo yum install php php-gd php-common php-soap

Restart Apache.

# sudo systemctl restart httpd

Test that PHP is working by creating a PHP test file that will display the PHP information page (watch out for the quotes if copy/pasting).

# sudo echo "<?php phpinfo(); ?>" > /var/www/html/test.php

Verify that the PHP information page loads by opening a browser and navigating to http://server_ip_address/test.php.

Create phpVirtualBox User Account

Create the account that the virtualbox web service will run as and to be used by phpVirtualBox.

# sudo useradd vboxweb
# sudo passwd vboxweb
# sudo usermod -a -G vboxusers vboxweb

Install phpVirtualBox

Download the latest stable phpVirtualBox package (5.2-0-rc1 at the time of writing)

# cd /tmp/ && wget https://github.com/phpvirtualbox/phpvirtualbox/archive/master.zip

Unzip/Extract phpVirtualBox package.

# sudo unzip phpvirtualbox-master.zip -d /var/www/html/
# sudo cd /var/www/html/ && mv phpvirtualbox-master/ phpvirtualbox/

Configure phpVirtualBox

Edit phpVirtualBox config.php file:

# cd phpvirtualbox/
# sudo cp config.php-example config.php
# sudo vi config.php

Change the username/password to the user that runs the VirtualBox web service.

...
var $username = 'vboxweb';
var $password = 'pass';
...

Set the user that the VirtualBox web service will run as.

# sudo echo "VBOXWEB_USER=vboxweb" > /etc/default/virtualbox

Restart the VirtualBox web service

# sudo systemctl restart vboxweb-service

Add SELinux Policy Exception

If you prefer not to disable SELinux then a policy exception will need to be added that allows phpVirtualBox to connect to the VirtualBox web service. First install the ‘policycoreutils-python’ package, which provides ‘semanage’.

# sudo yum install policycoreutils-python -y

Run the following command to add the exception.

# sudo semanage port -a -t http_port_t -p tcp 18083

Open a browser and to http://server_ip_address/phpvirtualbox. I’d recommend to use Firefox if you plan on using the console as this uses Flash, which will be blocked by Chrome. Use the default login username: admin and password: admin.

Accessing the Virtual Machine Console Remotely

You will have the capability to access the virtual machine console (to perform assisted installation, access the VM for troubleshooting, etc) using the rdesktop session through phpvirtualbox. You must enable ‘Remote Display’ support on the virtual machine settings, under ‘Display’. The port range defaults to 9000-9100, which should be fine unless you plan to run more VMs :).

In addition to enabling this feature, you will need to add an exception in the firewall to allow your client (web browser) to access the console.

# sudo firewall-cmd --zone=public --add-port=9000-9100/tcp
# sudo firewall-cmd --zone=public --permanent --add-port=9000-9100/tcp

You should now be able to access the VM’s console.

One final note. When connecting to the console, ensure to change the ‘Requested desktop size’ to ‘1024×768’ so that you are able to view the console properly.

0 0 votes
Article Rating

Related Posts

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Roel
Roel
6 years ago

Links are not working! Bad howto!

Victor M
Victor M
6 years ago

I follow instructions and phpVirtualBox is working!!!
Thanks!!!