October 6, 2019 · Programming Cheatsheets

Using VirtualBox for PHP Development


My Acer laptop, among other complaints, can't run a Linux distro properly. I am not a fan of dual-booting, as I hate maintaining two systems at once, so I tried a different approach: VirtualBox with Samba.

Why not use VirtualBox's Shared Folders instead?

Symbolic links are not supported on Linux guests if your host drive is NTFS. I can't mount my data drive as something other than NTFS because I also have other files on it and I need to access it from within Windows.

This means stuff like npm won't work. That's a no-no.

Setting up a Samba Share

On your Windows host, make sure the SMB 1.0 Server is installed. To do this, click on start, type appwiz.cpl and click on Turn Windows features on or off. Then, make sure SMB 1.0/CIFS File Sharing Support is checked (by default, it's only shaded). To make sure, expand the option by clicking the plus sign and check SMB 1.0/CIFS Server.

After clicking OK, it should set up the server. Now, we should allow VirtualBox's Host-Only Network through the Windows Firewall. Click Start, type Windows Defender Firewall with Advanced Security and click on Inbound Rules. Then, click on New Rule and use the following settings:

Once that's done, you can now share your folder. Right-click on your project root folder and click Share. Set it up as you would with any other share.

Accessing shares in your guest instance

I'm using Debian 10 for my development virtual machine, so adjust the instructions accordingly.

Debian 10 does not have sudo by default, so use su -. If you want to use sudo, run apt install sudo and add your non-root user to the sudo group.

Install cifs-utils

The cifs-utils package allows you to connect to and mount a Samba share.

sudo apt install cifs-utils

Create your Samba credentials

Create a new file in /etc/vboxsmb (if you change the filename, edit the mount configuration below) and add the following lines:

username=<your samba username>
password=<your samba password>
domain=<your workgroup domain>

If you're on Windows 10 and you have a Microsoft account connected, your username is your username without the @ sign, and your domain is the domain after the @ sign. For instance, if your Microsoft Account e-mail is example@outlook.com, your username is example and your domain is outlook.com.

Add your share to /etc/fstab

Edit /etc/fstab using your text editor of choice, and add the following line:

//192.168.56.1/lamp.devserver.local /home/liam/projects cifs credentials=/etc/vboxsmb,uid=1000,gid=1000,defaults,mfsymlinks 0 0

Remember to edit your file path if you didn't create the credentials file in /etc/vboxsmb. Also, yout uid and gid values should be equal to the Linux user you want to mount this share to. To get this, as the non-root user, run id. This is normally 1000.

Try mounting the share

As root, run the following command:

sudo mount -a

If there was no error, you should now be able to use your folder on both your Windows host and Linux guest.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket