Setup for development with VirtualBox
I have a nice setup for development with VirtualBox and nfs mounts, most credits go to @teranex (http://budts.be/weblog/).
the basic idea is to simulate every production environment with this setup, self using a Debian and Ubuntu machine setup.
here is an example on how to do this
on the development machine setup a development folder something like this
/home/<username>/develop/php
this is the path to the development environment on the dev machine in my case a laptop running ubuntu 11.04 with gnome3 then you have to download virtualbox and install it then install a ubuntu server.
With the server image running in the vm ( the tutorial here is a ubuntu server).
the only thing which is important is the setup of the network cards, here we need to setup 2 network cards
1) eth0 is set as host-only adapter
2) eth1 is set as bridged-adapter
here on the dev machine we install nfs-kernel-server, and on the VM we install nfs-common then alter the devs machines /etc/exports file and on the VM edit the /etc/fstab file. Ok lets do it, once you know what to do you can do this in 1 min or write a script in c, bash, python, ruby or a language you like.
Here is what i have done for the Ubuntu setup
1) First we gone install virtualbox
there are different ways to install virtualbox.
1) Go the the site and download it from the site
2) Checkout the svn source code
svn co http://www.virtualbox.org/svn/vbox/trunk vbox
3) Open terminal and type
$ sudo apt-get install virtualbox-ose
4) You can install it with the ubuntu software center and search for virtualbox.
Link: http://www.virtualbox.org/
Direct download: http://www.virtualbox.org/wiki/Downloads
2) Once we have installed the virtualbox you need to install an OS in the virtualbox appalication
to install an OS in vitrualbox is a other tutorial you can follow here
3) once you have installed the Ubuntu server vm image you can now start configuring the setup for to use as development.
4) before booting the vm you have to open the settings in the virutualbox image
images::/home/nico/develop/docments/img::nfs setup/
5) bootup your vm login and type
sudo apt-get install nfs-common
6) goto your physical machine back to the terminal and we going to install nfs-kernel-server
sudo apt-get install nfs-kernel-server
7) stay in the terminal and type
sudo vim /etc/exports
your file looks something like this
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
8) add a line to the end of the line something like this
/home/<username>/develop/php *(rw,sync,no_subtree_check)
9) in your vm window we first gone find out the IP so we can ssh to the vm type, also check if eth1 is enabled.
sudo ifconfig
here you get an list of all current networks connections something like this
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:44
eth1 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:0xx.xxx.xxx Bcast:0xx.xxx.xxx Mask:xxx.xxx.xxx.xxx
inet6 addr: 00000000000000000000000 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1106108 errors:1 dropped:0 overruns:0 frame:508746
TX packets:714355 errors:28 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1355354996 (1.3 GB) TX bytes:57076128 (57.0 MB)
Interrupt:23
lo Link encap:Local Loopback
inet addr:xxx.xxx.xxx.xxx Mask:xxx.xxx.xxx.xxx
inet6 addr: 000000000000000000000000 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:26963 errors:0 dropped:0 overruns:0 frame:0
TX packets:26963 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6530160 (6.5 MB) TX bytes:6530160 (6.5 MB)
if for example eth1 hase no ip the second rule 'inet addr:0xx.xxx.xxx' then you can type this commands
sudo ifconfig eth1 down
sudo ifconfig eht1 up
sudo dhclient eht1
this will ask for a new ip to the router and point a new ip to your network
if now know the current ip from eth0 something like 192.168.56.101
remember this or write it down
10) we need to know the ip of the pyhsical machine, here we also do the sudo ifconfig to know the current IP you should have something like vboxnet0 and it should have some ip like this 192.168.56.1
10 extra) to be chore your are connected you can always ping the ips like on the physical machine ping 192.168.56.101
you should get some output like this
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_req=1 ttl=64 time=7.38 ms
64 bytes from 192.168.56.101: icmp_req=2 ttl=64 time=5.86 ms
64 bytes from 192.168.56.101: icmp_req=3 ttl=64 time=3.90 ms
if something is wrong you see this output
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
From 192.168.56.1 icmp_seq=1 Destination Host Unreachable
From 192.168.56.1 icmp_seq=2 Destination Host Unreachable
on in the vm you type
ping 192.168.56.1
PING 192.168.56.1 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_req=1 ttl=64 time=7.38 ms
11) go back to the vm tis time to make the final 2 steps type
sudo vim /etc/fstab
and add a rule to the end of the file
192.168.56.1:/home/<username>/develop/php /var/www nfs rw,user,soft,nolock 0 0
save the file and type
sudo mount -a
ls /var/www/
and see you mount ;)