If you enjoy reading about weird software combinations let me tell you about my system configuration. I am currently using Windows 7 RC as my primary development OS (I quickly replaced my XP SP3) and I am finding it quite good to use (waiting for that new Fedora with the lovely Kde 4.2 to come out). In any case. I wanted to test how to set up Apache on a linux machine, but I didn’t want to go through the hassle of partitioning my HDD (not yet) so I decided to try Sun’s Virtual Box virtualization solution.
I got my Fedora 10 distro up and running in a jiffy, including the “Guest additions” that worked right out of the box (something that never really worked for me with VMWare). So, soon I started installing all the necessary packages for our project:
yum install Django
yum install python-psycopg2
yum install python-markdown
yum install python-dateutil
yum install mod_wsgi
I did have to download and install the PIL library by hand because I didn’t find the appropiate package for fedora and I already knew I could downlaod the tar.gz file from their site and use the infamous setup.py install command to install it.
The thing is, I want to keep my development files in sync with the files that were going to be served by Apache, that is, find a way to mount some sort of virtual drive connecting the virtualzied Fedora with the Windows 7 host. Thanks to Virtual Box’s shared folders options this was a breeze!
So I set up a shared folder on vbox’s shared folders menu, I pointed that to the trunk dir of our project and named it “mgtrunk”.
I refuse to mount this folder by hand each time, so I modified my fstab file and added a line like this at the end:
mgtrunk /mnt/mg vboxsf defaults 0 0
Obviously I created the “mg” folder at the “mnt” directory previosly :).
A quick reboot and everything was good to go.
The next step was configuring mod_wsgi (which was automatically generated by the yum installed), so I went on and edited the wsgi.conf file created under /etc/httpd/conf.d/
$ vim /etc/httpd/conf.d/wsgi.conf
I edited it adding lines like the ones in mod_wsgi’s integration with django wiki page relating to the Apache config. And also created a django.wsgi file in my django project under the apache/ dir, just like the aformentioned page mentions.
With a lot of expectations I started the httpd service, and rushed to http://localhost/ on my browser… BOOM… Cannot load the page, followed by a pesky SELinux ballon hovering on the screen. What to do? Disable SELinux through it’s administrative interface, I have no time tonight to mess with yer configs (I did try… chcon’ing some files… but errors just kept on appearing from nowhere! So I just disabled SELinux).
And after another reboot I got better results, the page was loading, but unfortunately no images or css where loaded. Apache was not service correctly images no css files or other files, the only thing that worked was the python scripts. Quickly I changed my config to check if an unmodified apache config worked (I overwrote the / directory with my mod_wsgi after all) and images were displayed correctly, how odd! I even uninstalled the mod_python extension to check if it wasn’t causing any conflicts! No luck…
Man this did take me time! As it turns out, Apache uses some sort of wicked kernel file transfer functionality to directly transfer files. This is how it reads on the httpd.conf file:
# EnableSendfile: Control whether the sendfile kernel support is
# used to deliver files (assuming that the OS supports it).
# The default is on; turn this off if you serve from NFS-mounted
# filesystems. Please see
Hmm… NFS… Network File System…. I even wonder if the vboxsf supports this sendfile functionality, maybe it doesn’t. So all it took me for the files to display correctly was DISABLING the darn sendfile directive. I added a line on my wsgi.conf file, just before the Directory tag for the media folder, that reads like this:
A final service httpd restart…. and… yay! The site’s working correctly, at last!
Quite an adventure… Now on I can go to try to develop a super scalable WSGI application to interface with my Django site like Eric Florenzano’s Writing Blazing Fast, Infinitely Scalable, Pure-WSGI Utilities blog article.