Skip to content

Instantly share code, notes, and snippets.

@wesruv
Last active January 31, 2022 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesruv/9e83e889a3ba94eca4b2b8552391058e to your computer and use it in GitHub Desktop.
Save wesruv/9e83e889a3ba94eca4b2b8552391058e to your computer and use it in GitHub Desktop.

Creating a Virtualbox Linux VM for local LAMP dev

Download and Install Virtualbox

https://www.virtualbox.org/wiki/Downloads Choose the version for the host machine, so if you’re on Windows, choose that, if Mac, choose that.

!IMPORTANT: On Windows, run the install for Virtualbox as Admin, if you do not network drivers for the VM won't be installed and VM's won't be able to connect to the internet.

Download Ubuntu Server

Or whatever flavor you like, I recommend this one. https://ubuntu.com/download/server

Creating the Machine

Click the “New” Icon

  1. Give the machine a name
  2. Type: Linux
  3. Version: Ubuntu 64

Next

Memory Size If you have 16GB or more RAM, I recommend giving it 4000MB of RAM. If you have less, 2000MB should be fine

Hard Disk Default option is fine

Hard disk file type Default option is fine

Storage on physical disk Default option is fine

File location and size Location is up to you, optimally the virtual disk is stored on an SSD The size depends on how much free space you have, running out of space is rough, it usually means you’ll have to create a new machine, unless you can get rid of a bunch of stuff. Expanding the disk storage of an existing VM is painful, I’ve looked it up a few times and each time starting from scratch was more appealing.

Minimum 50GB, I feel more comfortable with 100 or 150GB

Setting up the network interface(s)

Foreword:

There’s a choice here. There’s a “Host Only” feature (what I recommend), or “Bridged”.

“Host-only” means only your computer can see it, the network router and other computers on the local area network your on can’t see it. Since it’s locked off it’s a bit more secure.

“Bridged” means the Linux VM will show up like it’s another physical machine on the network. This is less secure, but can be useful if you want to test something from your phone, the phone will have a chance of seeing the the Linux VM, but there’ll may need to be host hacking on the router level to get that to work.

You could have both and keep the “Bridged” adapter off unless you’re using it.

Instructions

Select the VM you’ve made Click Settings (alternatively Machine > Settings works)

On the left side select Network

Leave Adapter 1 alone

Select Adapter 2

  1. Select: Enable Network Adapter
  2. Select “Host-only” (or “Bridged” if you prefer, see preface)
  3. Leave the default “Name:” that comes up

Press OK

Start the machine and Install Linux

Select your machine and press the “Start” icon

It will prompt you for a startup disk Press the folder icon and find the *.iso Ubuntu server install file you downloaded

Install Linux as normal Fill all options you’re prompted to, everything can be left on the default I typically don’t install any packages recommended from the end of the install process

See: the next doc Setting up a Linux box for local dev

Setting up fresh Linux for Local Dev

This is written for CLI (not that this couldn’t be done on a Linux install with a GUI) and written for Ubuntu.

Add packages necessary for build tools (useful for Node/npm)

sudo apt-get install build-essential

Add ssh package (if not already installed)

sudo apt-get install openssh-server

Add apache package (if not already installed)

sudo apt-get install apache2

Installing Samba on Ubuntu

Samba is a very fast file share over the network, great for working on files

Install from apt

sudo apt-get install samba

Edit it’s configuration

sudo nano /etc/samba/smb.conf

Under [global] settings add:

follow symlinks = yes
wide links = yes
unix extensions = no

At the end of the file add (but replace USERNAME with your linux username):

[USERNAME]
path = /home/USERNAME
available = yes
valid users = USERNAME
read only = no
browseable = yes
public = yes
writable = yes
wide links = yes
wide symlinks = yes
unix extensions = no

Restart samba

sudo service smbd restart

Enter desired password

sudo smbpasswd -a USERNAME

Connecting to Samba share

Find out the IP address on the Linux machine

ifconfig

Check for an IPV4 address (e.g. ###.#.#.##, 192.168.1.101, etc.)

Connecting to Samba share… on Windows

Press Windows Button + E to open a new explorer window In the title bar type two backslashes and an IP that you think will be the address to connect, e.g.

Right click on the folder with your username and select “Map Network Drive

Choose a letter you like, check both checkboxes (Sign in using different credentials and Reconnect at Login)

Now if you go to “This PC” in the side bar your Samba share will show up as a network drive with the letter you chose.

Connecting to Samba share… on Mac

In finder, under the menu Go > Connect to Server…

paste something like

smb://192.168.1.18/USERNAME/

replacing the ip address and username. Click the plus to save it as a favorite.

Add or create your SSH key

Locally, on a mac, if you have not generated an ssh key (look in ~/.ssh to see if there are keys there already), make a key

ssh-keygen

From a terminal on mac, to all in one go: copy your public keys, add them to authorized_keys, and set up the .ssh folder on the linux box

ssh-copy-id USERNAME@192.168.1.18

Or manually, to add an existing one, grab id_rsa and id_rsa.pub and copy it into a folder called .ssh in the root of the samba share (in linux it’s your home folder /home/USERNAME

Set the correct permissions on id_rsa

sudo chmod 200 ~/.ssh/id_rsa

Copying id_rsa.pub as authorized_keys will allow password-less login

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment