10 May 2009 at 19:08
filed under Uncategorized
Tagged debian, linux, os x
old -> updated version
This post will explain how to use a Debian virtual machine as a local server in OS X instead of the LAMP packaged by Apple.
If you’re like me and use OS X as your workstation but have a Debian production server, it could be very useful to be able to test your websites locally directly into a Debian server similar to your production one. To achieve that, we are going to install a Debian virtual machine in OS X and make them communicate by NFS. That way we will be able to develop with our favorite tool (like textmate) in OS X with our websites in ~/Sites being read by the Debian VM
1) First we need to install a VM engine (like VirtualBox) and install a Debian Linux with Apache, PHP. etc …
[EDIT]
By default the network adapter is in NAT mode and get its IP directly from your router, which means that you can’t access your VM if you’re not connected.
By using the “host-only adapter” mode you can access your VM at 192.168.56.3 (default IP, you can change that in VirtualBox preferences) with or without being connected to a network
-> “Settings / Network / Adapter 1 / Attached To” select “host-only Adapter”
[/EDIT]
[EDIT 2]
you can set up a second adapter as NAT to give internet access to the VM
-> “Settings / Network / Adapter 2 / Attached To “NAT”
and configure /etc/network/interface according :
auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet dhcp
(use ifconfig -a to get the right interface name : eth0, eth1, eth2, …)
[/EDIT 2]
2) Setup NFS export on OS X (you will need to be root for that) to allow NFS connection for the OS X user.
You need to know your user uid and gid. You can get them by typing (as your user, not as root) :
id
and you should get something like that :
uid=501(myusername) gid=20(staff)
Now setup the NFS export :
nano /etc/exports
and add this line :
/Users/myusername/Sites -network=192.168.0.0 -mask=255.255.0.0 -rw,no_root_squash,anonuid=501, anongid=20
then type
nfsd update
and
showmount -eif the NFS export is correct you should see :
/Users/myusername/Sites 192.168.0.0
3) Now on the Debian side we create the same user (myusername, uid=501, gid=20) :
adduser myusername --home /home/myusername --shell /bin/bash --uid 501 --gid 20
and we create a folder www in myusername home folder which will be the mount point for the NFS connection :
mkdir /home/myusername/www
chown myusername: /home/myusername/www
we install portmap and nfs-common:
aptitude install portmap nfs-common
and edit /etc/fstab to automatically mount the NFS connection at boot time :
nano /etc/fstab
and add this line (machostname is the OS X hostname) :
192.168.56.1:/Users/myusername/Sites /home/myusername/www nfs user,rw,exec 0 0
reboot (the Debian VM)
after reboot is completed you should be able to access the /Users/myusername/Sites content from OS X in the /home/myusername/www in the Debian VM
ssh 192.168.56.3 - l myusername5) configure apache
nano /etc/apache2/sites-available/default
NameVirtualHost * ServerAdmin webmaster@localhost DocumentRoot /home/myusername/www
and reload apache configuration :
/etc/init.d apache2 reload
voila, you should be able to see the website in Sites by going to the url http://192.168.56.3
KrisBelucci
Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.
AndrewBoldman
I really liked this post. Can I copy it to my site? Thank you in advance.