How to install VirtualBox on CentOS 7

Share on Social Media

Learn how to install VirtualBox on CentOS 7 with our comprehensive guide. Follow step-by-step instructions to set up and configure VirtualBox efficiently on your CentOS 7 system. #centlinux #linux #virtualbox

What is VirtualBox?

VirtualBox is a free and open-source hypervisor, developed by Oracle Corporation. VirtualBox supports all popular operating system platforms. VirtualBox is also used as the Provider for Vagrant, a server orchestration software.

What is phpVirtualBox?

phpVirtualBox is a web interface for administration of VirtualBox servers. phpVirtualBox is a free and open source web application. phpVirtualBox is written in PHP thus requires a Web Server with PHP language support for deployment.

install virtualbox on centos 7

Environment Specification

We have configured a CentOS 7 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 7.6
  • Hostname – virtualbox-01.example.com
  • IP Address – 192.168.116.185/24

Recommended Training: The Linux Command Line Bootcamp: Beginner To Power User from Colt Steele

3998050 2ed8
show?id=oLRJ54lcVEg&bids=1074530

Install VirtualBox on CentOS 7

Connect with virtualbox-01.example.com using ssh as root user.

Install VirtualBox prerequisite packages using yum command.

yum install -y kernel-devel-$(uname -r) kernel-headers gcc make perl wget

The vboxdrv.service requires same kernel-devel modules as of running Kernel. Otherwise, after installation vboxdrv.service will throw errors. Therefore, we have used $(uname -r) with above yum command

VirtualBox is distributed via its own yum repository. Therefore, we have to install VirtualBox yum repository first and then we will be able to install VirtualBox on CentOS 7.

Download and add VirtualBox yum repository in our Linux server.

wget https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repo

Build cache for VirtualBox yum repository.

yum makecache fast

Output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp3.isra.edu.pk
* extras: ftp3.isra.edu.pk
* updates: ftp3.isra.edu.pk
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
virtualbox/7/x86_64/signature | 181 B 00:00
Retrieving key from https://www.virtualbox.org/download/oracle_vbox.asc
Importing GPG key 0x98AB5139:
Userid : "Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>"
Fingerprint: 7b0f ab3a 13b9 0743 5925 d9c9 5442 2a4b 98ab 5139
From : https://www.virtualbox.org/download/oracle_vbox.asc
Is this ok [y/N]: y
virtualbox/7/x86_64/signature | 2.9 kB 00:05 !!!
virtualbox/7/x86_64/primary_db | 130 kB 00:01
Metadata Cache Created

Now we can install VirtualBox on CentOS 7 by using yum command.

yum install -y VirtualBox-6.0.x86_64

vboxdrv.service is automatically enabled and started by VirtualBox installation process.

Check status of vboxdrv.service.

systemctl status vboxdrv.service

Output:

â vboxdrv.service - VirtualBox Linux kernel module
Loaded: loaded (/usr/lib/virtualbox/vboxdrv.sh; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2019-07-15 21:38:55 PKT; 53s ago
Process: 33168 ExecStart=/usr/lib/virtualbox/vboxdrv.sh start (code=exited, status=0/SUCCESS)

Jul 15 21:38:55 virtualbox-01.example.com systemd[1]: Starting VirtualBox Lin...
Jul 15 21:38:55 virtualbox-01.example.com vboxdrv.sh[33168]: vboxdrv.sh: Star...
Jul 15 21:38:55 virtualbox-01.example.com systemd[1]: Started VirtualBox Linu...
Hint: Some lines were ellipsized, use -l to show in full.

VirtualBox 6.0 has been installed on our CentOS 7 server.

Install VirtualBox Extension Pack on CentOS 7

VirtualBox is splitted into two components.

  • Base Package
  • Extension Packs

We have already installed VirtualBox Base Package above. Now, we are installing VirtualBox Extension Pack to extend the functionality of VirtualBox software.

VirtualBox Extension Pack is available at VirtualBox Official Download Page. It consist of a single universal package that supports all platforms.

We are downloading it using wget command.

cd /tmp
wget https://download.virtualbox.org/virtualbox/6.0.8/Oracle_VM_VirtualBox_Extension_Pack-6.0.8.vbox-extpack

Install VirtualBox Extension Pack using VBoxManage command.

VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-6.0.8.vbox-extpack

Output:

Do you agree to these license terms and conditions (y/n)? y

License accepted. For batch installation add
--accept-license=56be48f923303c8cababb0bb4c478284b688ed23f16d775d729b89a2e8e5f9eb
to the VBoxManage command line.

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully installed "Oracle VM VirtualBox Extension Pack".

VirtualBox Extension Pack have been successfully installed on CentOS 7 server.

Configure vboxweb-service on CentOS 7

phpVirtualBox admin communicate to our VirtualBox server using vboxweb-service. Therefore, we have to configure vboxweb-service before installing phpVirtualBox.

Create a user that will run the vboxweb-service process.

useradd vbox
passwd vbox

Create a configuration file for vboxweb-service.

echo "VBOXWEB_USER=vbox" > /etc/default/virtualbox
echo "VBOXWEB_HOST=localhost" >> /etc/default/virtualbox

Restart vboxweb-service.

systemctl restart vboxweb-service.service

Allow vboxweb-service port in Linux firewall.

firewall-cmd --permanent --add-port=18083/tcp
firewall-cmd --reload

Install phpVirtualBox on CentOS 7

phpVirtualBox is a PHP based web application. Therefore, it can be deployed on a web server with PHP language support.

We are installing Apache HTTP server and PHP 5.4 along with other required packages using yum command.

yum install -y httpd php php-soap php-xml

Enable and start Apache service.

systemctl enable httpd.service
systemctl start httpd.service

Allow HTTP service in Linux firewall.

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

phpVirtualBox is free and open source web interface for VirtualBox. It is available at Github.

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

Extract master.zip file to Apache document root.

unzip master.zip -d /var/www/html/

Rename /var/www/html/phpvirtualbox-master directory for easy accessibility.

mv /var/www/html/phpvirtualbox-master /var/www/html/phpvirtualbox

Rename phpVirtualBox configuration file as follows.

mv /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php

Obtain the username and password defined in config.php file.

grep -e $username -e $password /var/www/html/phpvirtualbox/config.php

Output:

var $username = 'vbox';
var $password = 'pass';

The above values must match with the OS user vbox, that we have created above.

We have already created the OS user with the same username and password, otherwise you have to edit config.php to match it.

(Note: We are using an easy password for the sake of simplicity, but you are recommended to set a strong password here.)

Set SELinux boolean, so the Apache can access other network services.

setsebool -P httpd_can_network_connect on

Access phpVirtualBox Web UI

Browse URL http://virtualbox-01.example.com/phpvirtualbox/ in a client’s browser.

phpVirtualBox Login
phpVirtualBox Login

Login with phpVirtualBox default username/password (i.e. admin/admin).

phpVirtualBox Compatibility Warning
phpVirtualBox Compatibility Warning

After login phpVirtualBox web interface may display a compatibility warning and advise us to install a latest version of phpVirtualBox.

Since, we are already installing the latest version of phpVirtualBox therefore, we have no other option to ignore this warning until a new version of phpVirtualBox is available.

phpVirtualBox Dashboard
phpVirtualBox Dashboard

We are now at the Dashboard of the phpVirtualBox web interface.

Click on New to create a new virtual machine.

phpVirtualBox - Create Virtual Machine
phpVirtualBox – Create Virtual Machine

Provide virtual machine name and select operating system thereon and click on Next >>.

phpVirtualBox - VM Memory Size
phpVirtualBox – VM Memory Size

Set memory size and click on Next >>.

phpVirtualBox - VM Hard Disk
phpVirtualBox – VM Hard Disk

Select hard disk setting and click on Create.

image 239
phpVirtualBox – Hard Disk File Type

Select hard disk file type and click on Next >>.

phpVirtualBox - Storage on Physical Disk
phpVirtualBox – Storage on Physical Disk

Select Storage on physical disk and click on Next >>.

VirtualBox - File Location and Size
VirtualBox – File Location and Size

Select file location and size and click on Next >>.

phpVirtualBox - VM Created
phpVirtualBox – VM Created

Virtual machine has been created successfully.

One last thing is to change the default password of admin user.

Click on File > Change Password.

phpVirtualBox - Change Password
phpVirtualBox – Change Password

Set a strong password for admin user.

We have successfully installed VirtualBox and phpVirtualBox on CentOS 7 server.

Final Thoughts

Installing VirtualBox on CentOS 7 enables you to create and manage virtual machines easily, providing a flexible environment for testing, development, and learning. In this guide, we covered adding the necessary repositories, installing VirtualBox, and setting up the kernel modules required for smooth operation.

With VirtualBox successfully installed, you now have a powerful virtualization tool at your fingertips. Make sure to keep VirtualBox and your system updated to take advantage of the latest features, performance improvements, and security patches.

Struggling with AWS or Linux server issues? I specialize in configuration, troubleshooting, and security to keep your systems performing at their best. Check out my Fiverr profile for details.

Looking for something?

8 responses to “How to install VirtualBox on CentOS 7”

  1. BarakaMgala Avatar

    Hello,Thanks for your very practical guidance. i have an issue here, have followed through word by word.
    But unfortunately am getting this error(Failed to start VirtualBox Linux kernel module.)

    Please help.

  2. Ahmer M Avatar

    Hi, Please check the status of the VLKM service.
    systemctl status vboxdrv -l

  3. Adam F. Avatar

    Hi Ahmer! Thanks for this guidance, it's excellent! But I have a problem, I get to the page to login, enter admin/admin and I get this error. Could you tell me how can I fix it?
    Error logging in to vboxwebsrv
    Exception Object
    (
    [message:protected] => Error logging in to vboxwebsrv.
    [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] =>
    )

  4. Ahmer M Avatar

    Please verify that the username and password in config.php are correct.

  5. Adam F. Avatar

    I didn't find the error, but I installed it again and it works perfect. Thank you very much!!

  6. TimLa Avatar

    After wrestling with this via several other online tutorials, well, brother, you nailed it. Excellent work!

  7. Unknown Avatar

    Very appreciate for this tutorial, it helps me a lot. 👍

Leave a Reply