Setup OSQA on CentOS 5.5
This guide continues on from my previous guide on installing CentOS 5.5 on Hyper-V. Despite being based on CentOS, it should work on Red Hat Enterprise Linux, and principles will apply to many other Linux distributions as well.
Most of this is taken from the official OSQA documentation and modified slightly to fix a few problems I encountered along the way.
Getting Python2.6+
CentOS5.5 only comes with Python2.4, and unfortunately you can’t just upgrade it since many of the system tools rely on it.
Instead, you need to get hold of the latest Python you want and install it alongside Python2.4. At the moment, python2.7 is the latest stable version so I’m installing that:
Get Python Source from python.org. For 2.7 the URL is http://python.org/ftp/python/2.7/Python-2.7.tgz
cd /opt/ wget http://python.org/ftp/python/2.7/Python-2.7.tgz
Then extract and install:
tar -zxvf Python-2.7.tgz cd Python-2.7 ./configure --enable-shared make make altinstall
Get Python Setuptools for Python 2.7:
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea sh setuptools-0.6c11-py2.7.egg
Install the required Python Modules for OSQA
Easy_install ElementTree Easy_install Markdown Easy_install html5lib Easy_install python-openid
Install Apache and mod_wsgi
You’ll want Apache web server and mod_wsgi module for running the python code.
Get apache and apache devel installed if they aren’t already:
yum install httpd Yum install httpd-devel
Get mod_wsgi from http://code.google.com/p/modwsgi/downloads/list
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
This is the current version at the time of writing — you may want to check for a newer version.
Unpack and install it:
tar -zxvf mod_wsgi-3.3.tar.gz cd mod_wsgi-3.3.tar.gz ./configure --with-python=/usr/local/bin/python2.7
Make sure you specify the path to the python binary. If you leave it as default, it’ll use python2.4 which won’t work.
You can find out where your python binary is by issuing the following command:
whereis python
Once configure has completed, run make:
make make install
If you run in to problems, as I did, along the lines of "cannot load shared library libpython2.7….." then you might need to tell ldconfig to look in /usr/local/lib/ for shared libraries by either creating a new text file with "/usr/local/lib/" in it inside /etc/ld.so.conf.d/ and running ldconfig or you can just run ldconfig /usr/local/lib/ (add the -v option to make ldconfig verbose if you like).
Once that completes successfully you’ll need to load the module in apache.
Add the following line to /etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
Then restart apache:
/etc/init.d/httpd restart
Get Django
Next up, you’ll need Django.
Head over to http://www.djangoproject.com/download/ and get the latest stable release.
wget http://www.djangoproject.com/download/1.2.3/tarball/
Unpack and install:
tar -zxvf Django-1.2.3.tar.gz cd Django-1.2.3 python2.7 setup.py install
Make sure you use the python2.7 binary, and not the 2.4 version
Install PostgreSQL
I’m using PostgreSQL as my database backend – you may want to use something different though.
Get the latest version of postgres — 8.4 is the latest in CentOS repos at the moment.
Yum install postgresql84 Yum install postgresql84-server
Initdb:
service postgresql initdb
Modify the host connection settings for pgsql to allow TCP/IP connections.
Open /var/lib/pgsql/data/pg_hba.conf and add the following line to the bottom of top of the list (at the bottom of the file). You might also have to comment out the ‘ident’ version of the same line before it’ll work:
Host all all 127.0.0.1/32 md5
Start postgresql:
/etc/init.d/postgresql start
Switch to postgres user and create a user for OSQA to use:
[root@server opt]# su postgres bash-3.2$ createuser -P uosqa Enter password for new role: Enter it again: Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n bash-3.2$
Create db for osqa to use (again, as postgres user):
bash-3.2$ createdb -O uosqa osqa bash-3.2$
Install the postgresql84-devel package:
Yum install postgresql84-devel
Add the python adapter for Postgresql:
easy_install psycopg2
Install and configure OSQA
Get OSQA:
mkdir /opt/osqa cd /opt/osqa svn co http://svn.osqa.net/svnroot/osqa/trunk .
Create dirs and modify permissions:
cd /opt/osqa mkdir cache
Make the apache user the owner of the osqa directory:
chmod -R apache:apache .
Set permissions :
chmod u+w cache chmod u+w log chmod u+w forum/upfiles
Configure the osqa wsgi module:
Copy the osqa.wsgi.dist file to osqa.wsgi and modify it to match your installation.
Copy the settings_local.py.dist file to settings_local.py and configure to make your installation.
For the database you should provide the database name, username and password created before. Host should be ‘localhost’ and the database engine should be "postgresql_psycopg2".
You should also configure the APP_URL option to reflect the url that will be used to access OSQA.
Create the database tables:
cd /opt/osqa python2.7 manage.py syncdb
This will create the required table structure for OSQA using the settings you’ve provided. If it doesn’t work, check your configuration settings and ensure that postgresql is running.
Answer ‘no’ when prompted to create a super user — the first user to register with OSQA will become a super user.
Apache Integration
Create some directories to make Python/Django/WSGI happy:
mkdir -p /var/run/wsgi mkdir -p /var/python/eggs
You can also create a separate log directory for OSQA:
mkdir -p /var/log/httpd/osqa
Configure apache by creating a file called osqa.conf in /etc/httpd/conf.d/ and modify to match your install. It should look something like this:
WSGISocketPrefix run/wsgi WSGIPythonHome /usr/local/ WSGIPythonEggs /var/python/eggs #NOTE: all urs below will need to be adjusted if #settings.FORUM_SCRIPT_ALIAS !='' (e.g. = 'forum/') #this allows "rooting" forum at [http://example.com/forum], if you like <VirtualHost *:80> ServerAdmin admin@your.server.com DocumentRoot /opt/osqa/forum ServerName your.server.com #run mod_wsgi process for django in daemon mode #this allows avoiding confused timezone settings when #another application runs in the same virtual host WSGIDaemonProcess OSQA WSGIProcessGroup OSQA #force all content to be served as static files #otherwise django will be crunching images through itself wasting time Alias /m/ /opt/osqa/forum/skins/ Alias /upfiles/ /opt/osqa/forum/upfiles/ <Directory /opt/osqa/forum/skins> Order deny,allow Allow from all </Directory> #this is your wsgi script described in the prev section #this is your wsgi script described in the prev section WSGIScriptAlias / /opt/osqa/osqa.wsgi CustomLog /var/log/httpd/osqa/access_log common ErrorLog /var/log/httpd/osqa/error_log </VirtualHost>
And that should be it (if you believe the official OSQA install guide). Start apache and Postgresql and browse to your new OSQA installation. Create an account, login, and your first user will be an admin.
I found that this didn’t work first time for me, giving me a 500 internal server error. Checking the logs at /var/log/httpd/osqa/error_log (this path is configured in the apache config above) shows an error stating:
ImproperlyConfigured: Error loading psycopg2 module: cannot import name tz
There can be various causes for this, and this page has some good explanations: http://lethain.com/entry/2009/feb/13/when-psycopg2-can-t-import-tz/
I found the problem to be a combination of the server not being able to write to the Python Eggs path (/var/python/eggs) and also requiring the line os.environ['PYTHON_EGG_CACHE'] = ‘/var/python/eggs’ to be added to the osqa.wsgi file in /opt/osqa/.
How to get around this error?
[root@centos opt]# sh setuptools-0.6c11-py2.7.egg
python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory