Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Using FreeBSD 8.2-RELEASE. I want to mess around with Django and I want a working setup on my freebsd system. My understanding is I need to install python, apache, mod_wsgi, and django. The handbook section on Django talks about mod_python not mod_wsgi and I believe mod_wsgi is the recommended method.

I have the following installed on my system already from packages:

apache-2.2.17_1 
python26-2.6.6 

What do I have to do get django working with apache? Any tutorials?

share|improve this question
add comment

2 Answers

You don't have to install anything special to mess with Django. The only things you need for a debug server that works are:

  • Python
  • Django itself
  • Python modules for your DB if you want something other than SQLite

You have already got Python so I suggest:

easy_install pip
pip install django

Then follow the Django tutorials.
mod_wsgi comes into play when you deploy your application.

share|improve this answer
    
Thanks, in the end, I may go this route and I am familiar with the django development server. However I was looking to setup apache with mod_wsgi same as I use apache and php when testing my php sites. I want my development to somewhat match deployed environment. –  User Jun 24 '11 at 18:22
add comment
up vote 0 down vote accepted

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.