How To Install OSQA, Python, Django On Dreamhost Shared Hosting

Facebooktwittergoogle_plusredditpinterestmail

OSQA is a crowd-sourcing question answer forum based on Python and Django.  I do not claim this tutorial to be the best OSQA installation tutorial, but I’m sure as of today this is a better tutorial for OSQA installation on Dreamhost shared Hosting.  There are a couple of other tutorials on the web which are either stale or do not give importance to minute details and issues which come up during the installation, usually for Linux newbies.

Unlike most of the forum applications which run on PHP, OSQA runs on Python as a Django application.  Shared hosts like Dreamhost does not have OSQA as a one-click-install solution.  They do not provide root access to change/modify/install system files either. However, full access to the user profile is available hence, we install all the required applications in our user directory to setup OSQA.

So, let us start with the installation.  Things you would require are, Dreamhost shared hosting, SSH client like PuTTY and a shell account.

 

  1. Setting up your domain, user and database.

Setup Domain 

  • Login to your Dreamhost cPanel and click on Manage domains
  • Click on Add New Domain / Sub-Domain
  • Enter your domain name (subdomains can be used !).  For this tutorial i will use the name forum.amoghdesai.com
  • Select the user under which you want to install the domain and OSQA, or you can create a new user to keep it clean.
  • I created a new user called osqatest
  • Web directory will be automatically populated with your domain name.
  • Check the option Passenger (Ruby/Python apps only):
  • You will now get a pop up message which says Your web directory must end in /public to enable Passenger. Change this automatically?
  • Click on OK
  • Leave all other options as it is and click on Fully host this domain and your domain will be setup under the new users directory.

Setup User 

  • On the Dreamhost panel, click on Manage users => click on Edit next the newly created user => select Shell account under the User Account Type:, Shell type should be /bin/bash => Enter a new password and click on Save changes.

Setup Database 

  • On the Dreamhost panel, click on Manage Databases
  • Under Create a new MySQL database enter the new database name (in my case it is osqadb)
  • Type new hostname for the database host (eg: mysql.amoghdesai.com)
  • Create new database user and select a password (please note this user is different from the shell user created above.)
  • Click on Add new Database now!

 

  1. Login to the Shell account

  • If you don’t have an IP address to login to shell, on Dreamhost Panel got to => Manage domains => click on DNS under your domain name
  • Not down the IP Address at the bottom of the page (there will be multiple entries, you have to note the one next to SSH.yourdomain)
  • Download PuTTY from here.
  • Run PuTTY, enter the IP Address you noted in the above step and click on connect (click ok/Yes in the pop up box)
  • Enter your username and password you created in the steps above to login.
  • Type ls and hit enter, make sure you see your domain folder (in my case it is forum.amoghdesai.com)

 

  1. Install OSQA

There are a few things you need to remember while installing OSQA on Dreamhost shared hosting.

  • You don’t have root access to the server hence you cannot make changes or add extra modules to the webserver or Python.
  • OSQA runs as a Django application and Django runs on Python.  Dreamhost does have Python installed but it could be an old version
  • OSQA does not support Django 1.4. So we must install Django 1.3.1 for running OSQA successfully.
  • Once you are logged in to the shell account you should be in the home directory i.e. /home/username (in my case it is /home/osqatest)
  • Now create a new folder with command

mkdir python

  • Now run following command line by line to install python

wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2

tar -xjf Python-2.7.1.tar.bz2

cd Python-2.7.1

./configure -prefix=$HOME/python

make && make install

  • Confirm this by checking Python version using below command

python -V

and you should get the version Python 2.7.1

  • Delete the downloaded files using command

rm -rf rm Python-2.7.1*

  • Now set your new Python installation as the default installation.
  • go to your home folder, type cd and hit enter
  • edit the .bashrc file using the vi text editor, type the command:
  • vi .bashrc

  • You are now in the vi editor Press the Insert key on keyboard for edit mode
  • At the end of the file type this on the new line

PATH=~/python/bin:$PATH

 

  • press escape key to exit the editing mode, now type :wq and hit enter to save and quit and you will be back to the home directory
  • in the same manner install subversion, this is required to install the latest available version of OSQA
  • Run the following commands line by line

mkdir svn

wget http://subversion.tigris.org/downloads/subversion-1.6.15.tar.bz2

wget http://subversion.tigris.org/downloads/subversion-deps-1.6.15.tar.bz2

tar -xjf subversion-1.6.15.tar.bz2

tar -xjf subversion-deps-1.6.15.tar.bz2

cd subversion-1.6.15

./configure -prefix=$HOME/svn -with-expat=builtin -with-pic -with-ssl

make && make install

cd

vi .bashrc

 

  • Hit the Insert key on the keyboard and At the end of the file type this on the new line

PATH=~/python/bin:~/svn/bin:$PATH

  • Press escape key to exit the editing mode, now type :wq and hit enter to save and quit and you will be back to the home directory.
  • Now reload the .bashrc to effect the changes we made using command

source .bashrc

  • Now install Django 1.3.1 and other required python modules.

To install python modules you can either use easy_install or pip.  In this tutorial I have used easy_install for all the modules and pip is only used to install Django.  This is because only Django 1.3.1 works with OSQA right now and pip has the option to install specific version (which easy_install doesn’t). Lets start.

wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg

sh setuptools-0.6c11-py2.7.egg

easy_install pip

easy_install flup

easy_install mysql-python

easy_install html5lib

easy_install markdown

easy_install south

easy_install python-openid

pip install django==1.3.1

  • And finally Install and configure OSQA

 cd ~/your_domain /

svn co http://svn.osqa.net/svnroot/osqa/trunk

mv trunk osqa

cd osqa

cp settings_local.py.dist settings_local.py

vi settings_local.py

 (Important: replace “your_domain” with the domain name you created) 

  • Hit the Insert key on the keyboard and scroll to the lines

DATABASE_NAME = ‘my_database’
DATABASE_USER = ‘my_user’
DATABASE_PASSWORD = ‘my_password’
DATABASE_ENGINE = ‘mysql’  #mysql, etc
DATABASE_HOST = ‘mysql.my_domain.com’
DATABASE_PORT = ” #leave empty for dreamhost

 

  • Fill all the above details with our database information (leave the port blank)
  • Press escape key to exit the editing mode, now type :wq and hit enter to save and quit.
  • Once the database information is given to OSQA, prepare the database by

cd ~/your_domain/osqa

python manage.py syncdb –all

  • When it prompts for creating a user type no and hit Enter

python manage.py migrate forum –fake

 (Important: replace “your_domain” with the domain name you created)

  • Create the passenger_wsgi.py file

cd ~/your_domain/

vi passenger_wsgi.py

  • Hit the Insert key on the keyboard and type (you can copy paste the below text as it is and then replace the username and domain name values)

 import sys, os
INTERP = “/home/your_shell_username/python/bin/python2.7”
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(‘/home/ your_shell_username/your_domain)
sys.path.append(‘/home/ your_shell_username/your_domain/osqa’)
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘osqa.settings’
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

 

(Important: replace “your_domain” and “your_shell_username” with the domain name and shell userid you created). 

  • Press escape key to exit the editing mode, now type :wq and hit enter to save and quit.
  • Now restart python using following command

Pkill python

 Your OSQA installation is now complete.  Open a web browser and open your new OSQA domain name and you should be good to go !!

(Important: As soon as you log-in create a new user, your 1st user is the admin user)

 

Amogh Desai

Amogh Desai

A System Admin by profession, is a tech buff and a licensed Amateur Radio operator with callsign VU3DES. He is interested in Technology, Amateur radio, Electronics home-brewing, FOSS, Photography and everything tech. He uses this blog to share his views and ideas with people sharing similar interests.
Amogh Desai
Facebooktwittergoogle_plusrssyoutube

3 Comments


  1. Hi Amogh,

    I have installed python2.7 and django on bluehost. But the result is 500 error :(. Tried so many times but it’s not successful. I have seen your tutorial it’s excellent but it is for dreamhost.

    Thank you

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *