Multiple Websites & Shared Folders With VirtualBox On Windows 11 Host


This guide will show you how to set up multiple websites to run from your development server using Ubuntu on VirtualBox. You will be able to work on your files from your Windows host machine and view them in your preferred browser before uploading them to your live server.

Prerequisites

  • VirtualBox: Make sure you have the latest version installed on your Windows 11 machine.
  • Ubuntu VM: Install Ubuntu as a virtual machine in VirtualBox.
  • LAMP stack: Set up Apache, MySQL, and PHP on your Ubuntu VM.

If you haven’t already set up your virtual machine, you may want to check out our guide on setting up an Ubuntu LAMP server running on VirtualBox.

Setting Up Available Sites

The default location for your websites on the Apache server is /var/www/html. You should create a folder for each of your websites using the terminal as follows:

sudo mkdir /var/www/html/newsite 
sudo mkdir /var/www/html/newsite2 
sudo mkdir /var/www/html/newsite3

Configure Virtual Hosts

For each website, you need to set up a virtual host configuration file. Copy the default configuration file and edit it for your new website:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/newsite.conf

Edit the new file:

sudo nano /etc/apache2/sites-available/newsite.conf

Update the configuration file to look like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName newsite
    DocumentRoot /var/www/html/newsite

    <Directory /var/www/html/newsite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/newsite_error.log
    CustomLog ${APACHE_LOG_DIR}/newsite_access.log combined
</VirtualHost>

Enable the New Site

Disable the default site if necessary and enable your new website:

sudo a2dissite 000-default.conf
sudo a2ensite newsite.conf

If you need mod_rewrite, enable it using:

sudo a2enmod rewrite

Restart Apache to apply the new settings:

sudo systemctl restart apache2

Repeat these steps for each website you want to set up on the server.

Setting Up Shared Folders from the Windows Host

  • Shut down your virtual machine: In VirtualBox, select your VM, and open the settings.
  • Create shared folders: Go to the ‘Shared Folders’ section and create a share for each website on your Windows host machine. Assign a unique name to each share. For example, newsite.
  • Start your virtual machine.

Mount Shared Folders in Ubuntu

Mount the shared folder to link it with the Apache website folder. Replace newsite with your share name:

sudo mount -t vboxsf newsite /var/www/html/newsite

Note: To automatically mount the shared folder at boot, add the following line to your /etc/fstab:

newsite /var/www/html/newsite vboxsf defaults 0 0

Setting a Dev URL Using the Hosts File

If you set up your virtual machine to use a static IP, you can map a custom URL to it using the Windows hosts file.

  1. Open the Windows hosts file:
    Open C:\Windows\System32\drivers\etc\hosts in a text editor with administrative privileges.
  2. Add a custom domain mapping:
    Append the following line, replacing 192.168.1.85 with your VM’s IP and dev with your preferred domain:
192.168.1.85 newsite.dev
  1. Access your site:

You can now open http://newsite.dev in your browser to access your website.