November 22, 2024, Friday, 326

Install OSQA on Snow Leopard

From NeoWiki

Jump to: navigation, search


Prerequisites

Python

We can use the built-in Python 2.6.1 in OS X 10.6.5 at /usr/bin/python, or we can use MacPorts to install the newest Python 2.6.6 at /opt/local/bin/python.

setuptools

Download from here and install it or just let MacPorts install the py-setuptools package at /opt/local/bin/.

Apache Web Server

Just use built-in setup, the 64-bit Apache 2.2.15 in OS X 10.6.5.

mod_wsgi

Which is not in the default setup of Snow Leopard. We can download the newest source version from here and compile and install it like this:

curl -o mod_wsgi.tgz http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
tar -xzf mod_wsgi-3.3.tar.gz
cd  mod_wsgi-3.3
./configure
make
sudo make install

These steps will compile mod_wsgi.so and install it into /usr/libexec/apache2.

Now edit your Apache config file /etc/apache2/httpd.conf, add this line to the bottom of the LoadModule list:

LoadModule wsgi_module libexec/apache2/mod_wsgi.so

Installation

Install Django and Other Packages

Make sure setuptools has been correctly installed and the easy_install can be access in your system path. Then run:

sudo easy_install django
sudo easy_install html5lib
sudo easy_install markdown
sudo easy_install python-openid
sudo easy_install south
sudo easy_install django-debug-toolbar
sudo easy_install mysql-python

Check Out Newest OSQA Source

Actually you can checkout it to anywhere you want, but I just put them in the Python site-packages folder, and prepare some folder privileges:

export OSQA_HOME=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa
sudo svn co http://svn.osqa.net/svnroot/osqa/trunk/ $OSQA_HOME

sudo mkdir $OSQA_HOME/cache
sudo chmod 777 $OSQA_HOME/tmp
sudo chmod 777 $OSQA_HOME/log
sudo chmod 777 $OSQA_HOME/forum/upfiles
sudo chmod 777 $OSQA_HOME/cache

Prepare the Database

First using your favorite tool to setup the database for OSQA, for me it's CocoaMySQL (Sequel Pro is just a shame!).

  • Create a database with the name 'osqa';
  • Create a user with the name 'osqa' and whatever password you like;
  • Give all permissions of database 'osqa' to user 'osqa@localhost'.

Populate Initial Data

First we must config the OSQA to use the database we've just created:

cd $OSQA_HOME
sudo cp settings_local.py.dist settings_local.py
e settings_local.py

Find the database configuration part and change them like these lines:

DATABASE_NAME = 'osqa'
DATABASE_USER = 'osqa'
DATABASE_PASSWORD = 'your_password'
DATABASE_ENGINE = 'mysql'
DATABASE_HOST = '/var/mysql/mysql.sock'
DATABASE_PORT = 

If you are not using MySQL via mysql.sock file, you can change the DATABASE_HOST variable to match your setup.

Now populate initial data using the tool from OSQA:

cd $OSQA_HOME
python manage.py syncdb --all
python manage.py migrate forum --fake
Tools clipart.png Warning: You will be prompted to create a new "super user". You should promptly answer "NO". Once you get your site running, create a new user through the normal OSQA account creation process and that will be your super user.
Tools clipart.png With South installed, you have the ability to migrate between databases - a useful feature as OSQA is updated. However, as this is a fresh install, you will need to convince South that the schema is already up to date by "faking" a migration. That is what the last line above does.

Config Apache WSGI To Go

Save the content below to a file named osqa-wsgi.conf in /etc/apache2/:

# mod_wsgi configuration directives - I like having stdout access, the other two
# options run mod_wsgi in daemon mode - more on this in a minute.
WSGIPythonHome /opt/local/Library/Frameworks/Python.framework/Versions/2.6/
WSGIRestrictStdout Off
WSGIDaemonProcess django
WSGIProcessGroup django
 
Alias /m/ /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa/forum/skins/
Alias /upfiles/ /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa/forum/upfiles/
 
Alias /admin_media/ /Users/neo/Code/Python/Django/django/django/contrib/admin/media/
 
<Directory /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa/forum/skins>
	Order deny,allow
	Allow from all
</Directory>
<Directory /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa>
	Order deny,allow
	Allow from all
</Directory>
 
<Directory /Users/neo/Code/Python/Django/django/django/contrib/admin/media>
	Order deny,allow
	Allow from all
</Directory>
 
WSGIScriptAlias /osqa /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa/osqa.wsgi
 
CustomLog /var/log/apache2/osqa/access_log common
ErrorLog /var/log/apache2/osqa/error_log

Make sure that all the folders are set correctly. The '/admin_media/' alias should point to the Django admin media files, which come from the Django distribution (typically under 'django/contrib/admin/media' sub-folder).

Then add it to Apache by add following line to the very end of httpd.conf:

Include /private/etc/apache2/osqa-wsgi.conf

Now go to OSQA home to make the mod_wsgi config complete:

cd $OSQA_HOME
sudo cp osqa.wsgi.dist osqa.wsgi
e osqa.wsgi

In my case, the osqa.wsgi should be like:

#!/opt/local/bin/python
import os
import sys
sys.path.append('/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages')
sys.path.append('/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/osqa')
# The first part of this module name should be identical to the directory name
# of the OSQA source.  For instance, if the full path to OSQA is
# /home/osqa/osqa-server, then the DJANGO_SETTINGS_MODULE should have a value
# of 'osqa-server.settings'.
os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
 
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Almost done!

Final Hacking

Now we can access our new OSQA at http://localhost/osqa and create our first user (which will be the super user) and have some test on features. In my case I run OSQA at a sub-folder of the host, and there is some bug in the OSQA code, which prevents the tag auto matching function working. Fortunately this is a easy-to-fix bug, just open $OSQA/forum/skins/default/templates/ask.html and find the following line:

$("#id_tags").autocomplete("/matching_tags/", {

and change it into:

$("#id_tags").autocomplete("../../matching_tags/", {

Hope it'll be fixed officially soon.

Still testing... if any new info I will update here :)