Ok I got this working mostly with help from the following instructions: http://code.google.com/p/modwsgi/wiki/InstallationOnFreeBSD
Here's what I did (as root user):
Reinstall apache
I already had apache22 installed from a binary package but apparently the package version is compiled without thread support and you need threads for mod_wsgi. So I did:
pkg_delete apache-2.2.17_1. This complained about php depending on apache, so I did: pkg_delete php5-5.3.5. Then I did pkg_delete apache-2.2.17_1 again which worked. Then I did cd /usr/ports/www/apache22 then make config then I checked the check box "[X] THREADS Enable threads support in APR" then make then make install. Starting apache worked but I got an error "[warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter". I searched online and fixed it by doing kldload accf_http and apachectl restart then I added accf_http_load="YES" to my /boot/loader.conf so this change would persist after reboot.
Install mod_wsgi
cd /usr/ports/www/mod_wsgi3
make
make install
this automatically modified my httpd.conf file to add a loadmodule line
Resinstall php
(not strictly necessary but since I had to deinstall it above)
cd /usr/ports/lang/php5
make config (and set any options desired)
make
make install
Test mod_wsgi install
Following instructions at http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide.
I created a file called test.wsgi with the following content in my document root:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
I added the following line to the end of my httpd.conf:
WSGIScriptAlias /myapp /usr/home/myusername/www/wsgitest/test.wsgi
(On my test box I have apache setup with a document root at /usr/home/myusername/www). Then I did apachectl restart. Then I went to http://localhost/myapp in my browser and voila! I saw "Hello World".
Install pip
cd /usr/ports/devel/py-pip
make
make install
Refreshed my shell so path would update.
Install django
pip install django
(this got me django version 1.3 yay!)
to confirm django install
python
import django
Create django test app
I created a new folder for my django test mkdir /usr/home/myusername/www/djangotest. Then
django-admin.py startproject mysite
Create django wsgi file
created a new file /usr/home/myusername/www/djangotest/django.wsgi with the following content:
import os
import sys
path = '/usr/home/myusername/www/djangotest'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Edit httpd.conf
WSGIScriptAlias /djangotest /usr/home/myusername/www/djangotest/django.wsgi
apachectl restart
visit http://locahost/djangotest in browser. It works!
Edit httpd-vhosts.conf (optional)
Now to get it working as part of virtual host. Comment out the WSGIScriptAlias line in httpd.conf. Then add something like:
<VirtualHost *>
ServerName mytest.whatever
DocumentRoot /usr/home/myusername/www/djangotest
WSGIScriptAlias / /usr/home/myusername/www/djangotest/django.wsgi
</VirtualHost>
apachectl restart
After configuring hosts file, visit http://mytest.whatever in browser. It works!