I like my linux to be as clean as possible and therefore hate packages with gazillions of dependencies, that I may only need once.  I tend to forget about these packages and they are then sitting there, eating precious SSD space (where my root system is located). Especially when it comes to webdevelopment, webservers etc. this bugs me a lot, since a working LAMP server together with Python and all the extensions I need takes up a lot of space, config files in /etc and consists of many packages. This is why I recently switched to a virtual machine as development server. The advantages are the following:

• I can separate all the webserver and scripting language stuff from my root filesystem
• It is portable
• I can use a distribution similar to the one running on my (real) webserver, which makes deployment easier.
• It works (nearly) exactly as if I used the main filesystem, since today’s computers are powerful and memory big enough.

I will outline briefly what I did:

1. Install Debian in a VirtualBox VM without graphical interface (that option is displayed during the Debian installation)
2. Start the VM once with VirtualBox and configure SSH access
3. Configure Port forwarding for ports 80 and 22 (HTTP and SSH) in VirtualBox: Go to the “Network” Settings of the VM, expand the “Advanced Settings” of “Adapter 1” (should be attached to NAT) and click on “Port Forwarding”. Now map the host ports 8080 and 2222 to 80 and 22 respectively. (You can of course feel free to use the ports you like)
4. When SSH access (localhost:2222) works, shut down the VM. You will now always use the VBoxHeadless tool to start it, which starts the VM in the background. (Attention: Don’t forget it after you are done working. It eats up a lot of memory!)

To control the VM and ease access to it, you can create an init script or a systemd service. Here is the latter one I use:

[Unit]
Description=Webserver

[Service]
Type=simple
ExecStart=/usr/bin/vboxheadless --startvm "NAME_OF_WEBSERVER_VM" --vrde off
ExecStop=/usr/bin/VBoxManage controlvm "NAME_OF_WEBSERVER_VM" savestate
Restart=always
User=YOUR_USERNAME


Also, you should configure your SSH to have an easy shortcut to access the server:

Host SHORTCUT
Hostname localhost
Port 2222
User SHORTCUT


There are two options to work on the files.

1. Use sshfs: sshfs SHORTCUT webserver/ and then work within this directory. (It mounts the webserver using SSH) This is my preferred way, since the files are then stored on the VM.
2. Use Virtualbox’s shared folder feature.

All urls defined in /etc/hosts on the host machine should be redirected on the vm if you append :8080 to the address.

I hope, some of you find the idea useful.

# Comments

No comments yet. Consider writing one!