I had a bad morning trying to repair my Cygwin installation from a virtualenv mess. It’s time to get a Debian and install it on a Virtualbox for my new django project!
- Windows: host
- Debian: guest
Choosing the distro: what I want
- Python 2.6
- Django 1.4
- Apache + Mysql
I’m a Debian fan from years so I go to the Debian website and download Wheezy netinst iso (32 bit, since I’m on a 32 bit OS and I want to use more core): wheezy met all the requirements above.
I already have a Virtualbox, so what I do is to add a new virtual disk and to add the new Wheezy netinst iso on CD/DVD images. Then I create a new Debian machine (32 bit) with two cores. I choose the iso image to be mounted on startup so the Debian setup process will start on boot.
As network device, I choose the Bridge option, so I can access the machine later from my windows host.
Installing the system
When you turn your machine on, many choices will be prompted to you. I install the webserver (apache) from the list, removed SQL server and print server and then leave desktop selected and the other default values. After some minutes Debian is installed and I can log in with the credential I have specified during installation.
Use WORKGROUP as network name if you’re running a Windows host when asked.
Install django packages
Under the Application menu, find the Debian package management tools to install what you want. As the requirements I’ve listeded above I search and install those packages:
- python-django (1.4.1-2)
Later you can install more useful packages like virtualenv and phpmyadmin.
After you’ve installed those packages, you can do some test. Open a shell (Accessories > Terminal) and then type these commands:
What version of python I’m running?
Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38)
[GCC 4.6.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
So I’ve python 2.7. Good!
>>> import django
(1, 4, 1, ‘final’, 0)
And I’ve Django 1.4.1.
Share your code to the Windows network (workgroup)
Now I want to read the code from one machine to another. I choose Samba server to read and write files from the virtual machine to windows and back. It will be useful since I’ve a complete Eclipse + pydev IDE on windows and I love work with it.
I open a Root terminal and type:
If you choosed the Bridge network interface on installation, you will got something like this:
eth0 Link encap:Ethernet HWaddr ??????
inet addr:192.168.0.104 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: ???????????/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:49280 errors:0 dropped:0 overruns:0 frame:0
TX packets:19777 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:45400047 (43.2 MiB) TX bytes:1887849 (1.8 MiB)
Interrupt:19 Base address:0xd020
The address in bold (192.168.0.104) is the local network address of my virtual machine. If I just type this address in the Chrome browser it’s running on Windows (host) I got the “It works!” from Apache on the virtual machine. If you can’t see nothing, left click on the network icon on the bottom of your virtualbox windows > click on the menu voice and then choose the Bridge option. Then redo the ifconfig as above.
Create a directory to store your django code (inside current user home folder). Open the terminal as normal user:
$ mkdir my-django-code
Then share this folder with samba. To do this, let’s create a new user without a password:
adduser guest –home=/home/public –shell=/bin/false –disabled-password
Then add these lines to /etc/samba/smb.conf on “## Authentication ##” section:
security = share
guest_account = guest
invalid_users = root
obey pam restrictions = yes
And then after the [cdrom] commented text:
read only = no
locking = no
path = /home/myuser/my-django-code
guest ok = yes
force user = myuser
Where myuser is my (normal) user name. The lines above tell something like this to samba:
- Let a guest user access without a password
- …to the path /home/myuser/my-django-code
- …”masquerading” like myuser
The “masquerade” thing is all about having the right to write files created from myuser from the guest user on the host.
When i browse my Workgroup on windows, I found the machine name I choose during installation and inside I found the my-django-code directory. I try to read and write files from the host (Windows) and from the guest (Debian) and it’s all ok.
If you’re starting to develop on django, so this howto for beginners will help you a lot. Since I’ve installed the python-django package from Debian, to start a project is simple as typing this:
$ cd my-django-code
$ django-admin startproject django_unchained
$ cd django_unchained
$ python manage.py runserver 192.168.0.104:8000
Where 192.168.0.104 is the virtual machine local network address from above and 8000 the port of the django testing webserver.
on Crome (host: Windows) and I get the hello page from Django. Perfect!
Then, I can just follow the django howto to do the right things during the creation of my new app django_unchained!