In this tutorial I will show you how did I setup OSQA(Open Source Question Answer) on my shared HostMonster hosting. This tutorial should also be valid for most of the other shared hosting environments like DreamHost, HostGator, BlueHost, GoDaddy etc. As the method shown here is very generic.
If you have any issues please post below OR you can use My Services to handle all of this.
OSQA (Open Source Question Answer forum) runs as a Django application. Django runs on Python. Though HostMonster have Python installed but it is an older version, and you don’t have the privilege to install new python packages. So we will install our own Python in this tutorial.
Prerequisites:
- A Reliable Web Hosting (DREAMHOST – Use Promo Code “BESTDISCOUNT2011” for a whopping $47 Discount!)
- You need Shell/SSH access to your hosting server. Contact your web hosting support for same.
- Putty Client
Procedure to Install OSQA, Django, Python, SVN on your HostMonster shared web hosting account. (Should be valid for other web hosting servers also)
- First Login to your SSH Client(Putty) using your credentials.
- Python
Create a directory named “python” where your Python executable will reside.
mkdir python
Now download ,extract, compile and then install the source for Python 2.7.1 (We are not using Python 3.1 because currently Django does not support Python 3 and won’t for at least a year)
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 –j8 && make installmake –j8 will speed up building as it will be executed in 8 concurrent threads.
Now check if Python was installed perfectlycd
./python/bin/pythonPython 2.7.1 (r271:86832, Jan 16 2011, 06:48:41)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> exit()If above message is displayed then your python installation is fine. You can now remove the sources.
rm Python-2.7.1.tar.bz2
rm -rf Python-2.7.1/Now add the Python executable to the $PATH ,so that preference to our newly installed Python is given and can be accessed from anywhere easily.
cd
pico .bashrcPico text editor will open the .bashrc file, and at the end of the file add the following line
PATH=~/python/bin:$PATH
Then save the file by Ctrl + O and then Ctrl + X
After saving the file you need to reload the .bashrc file by
source .bashrc
- SVN
Now it’s time for Subversion. You install subversion in second place because it will build a python extension. The first step, as before, is to download, unpack and create a destination directory:
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.bz2Now configure, make and install svn in the directory we created.
cd subversion-1.6 .15
./configure -prefix=$HOME/svn -with-expat=builtin -with-pic -with-ssl
make && make installTo check if SVN was installed successfully.
cd
./svn/bin/svn --versionsvn, version 1.6.15 (r1038135)
compiled Jan 16 2011, 07:18:45Now add the SVN executable to the $PATH ,as we did with Python executable
cd
pico .bashrcPico text editor will open the .bashrc file, and at the end of the file add the following line
PATH=~/python/bin:~/svn/bin:$PATH
Then save the file by Ctrl + O and then Ctrl + X
After saving the file you need to reload the .bashrc file again by
source .bashrc
- Python Modules and Packages
Now we will install Python modules and packages like setuptools : easy_install, flup, MySQL-python, Django. First of all we will install setuptools as it will make installing flup and MySQL-python easy.wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.eggNow as Setuptools: easy_install is installed, lets proceed installing Django and other dependencies
easy_install flup
easy_install mysql-python
easy_install Django
easy_install html5lib
easy_install markdown
easy_install south
easy_install python-openid - OSQA
Now Lets install OSQA or Open Source Question Answer on your server. First of all we will download the svn version of OSQA.
cd
svn co http://svn.osqa.net/svnroot/osqa/trunk
mv trunk osqa
cd osqa
cp settings_local.py.dist settings_local.py
pico settings_local.py
Now settings_local.py will open in Pico editor, Now enter the Database Name and database user details and save the file by Ctrl + O and Ctrl +X
Now that you have filled the database details, you need to prepare the Database by:
cd ~/osqa
python manage.py syncdb –all
python manage.py migrate forum --fakeEnter NO when prompted to create a new user
Now create a directory in public_html or www , where you want your domain to refer to. Like I have created myosqa in public_html where I have referred the forum.techgeekguy.com to
cd
cd public_html
mkdir myosqaNow create .htaccess file and enter the following in the .htaccess file in this directory
pico .htaccess
AddHandler fcgid-script .fcgi # For security reasons, Option followsymlinks cannot be overridden. #Options +FollowSymLinks Options +SymLinksIfOwnerMatch RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(adminmedia/.*)$ - [L] RewriteCond %{REQUEST_URI} !(osqa.fcgi) RewriteRule ^(.*)$ osqa.fcgi/$1 [L]
Save the .htaccess by Ctrl + O and Ctrl + X
Now create a file named osqa.fcgi and add the following code in it with changes as per your server like username, directory structure etc.
pico osqa.fcgi
#!/home/your_username/python/bin/python import os, sys sys.path.insert(0, "/home/your_username/") sys.path.append("/home/your_username/osqa") os.chdir("/home/your_username/osqa") os.environ['DJANGO_SETTINGS_MODULE'] = "osqa.settings" from django.core.servers.fastcgi import runfastcgi runfastcgi(method="threaded", daemonize="false")
Save the osqa.fcgi by Ctrl + O and Ctrl + X
Make osqa.fcgi executable by
chmod +x osqa.fcgi
Now as everything is setup, In your cpanel set a sub-domain or main domain where you want your osqa site to sit at, redirect to the folder ~/public_html/myosqa
And you are ready to go!
Note: Restarting the spawned server
If you change any Python code , or settings of osqa on your site, you’ll need to tell FastCGI the code has changed. You can do this by touching the fcgi file and the Django application will restart.
touch ~/public_html/myosqa/osqa.fcgi
{ 10 comments… read them below or add one }
You are my hero, dude. I finally got around to getting shell access to find that the latest version of Python HostMonster has is Python 2.4. Yuck. Props.
Thank you! What a clear description. This article is perfect.
Hi i tried it with hostgator and it didnt work. do you know of anyone who has successfully done it on hostgator? thank you.
Thank you for this helpful article. I did this on my DreamHost server. I skipped the SVN installation, because I wanted to install the official “stable” release of OSQA. May be that’s why a couple of errors showed up, but I fixed them with the solution I found on the OSQA site.
Thanks again!
hello sir,
i want it to install. but i have no knwledge of all these. i have linux hosting. so please if you can help me.
One of the best article for me as a beginner of django. Thank you Keshav.
in the osqa.fcgi,
be sure to write the “import os, sys” in a new line, python is fussy abt indentations (i kept getting 500 Internal server error)
——-
#!/home/your_username/python/bin/python
import os, sys
sys.path.insert(0, “/home/your_username/”)
sys.path.append(“/home/your_username/osqa”)
os.chdir(“/home/your_username/osqa”)
os.environ[‘DJANGO_SETTINGS_MODULE’] = “osqa.settings”
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method=”threaded”, daemonize=”false”)
—-
also, u can always check that django and osqa is properly setup or not by first trying a development server (if u are unsure of the fcgi mod or misformed htaccess errors) by running in ur OSQA trunk…
according to this example:
somguy@somedom.com[/home/osqa] python manage.py runserver yourdomain name.com:anyport
then go on and visit yourdomainname.com:anyport (u wrote above) to see if u see osqa working.
you can also use your IP address instead of yourdomainname.com.
to tes ton port 80, u need sudo-powers.
Hope this helps.
This was a nice article, thanks Keshav ji.
Hello! I could follow most steps but I am unable to install setup-tools. I am installing on a distributed computer cluster and getting this error:
ERROR: certificate common name `*.a.ssl.fastly.net’ doesn’t match requested host name `pypi.python.org’.
Unable to establish SSL connection.
Please help!
I used git to get an OSQA version that was compatible with Django 1.6 on Dreamhost.
git clone https://github.com/udacity/osqa.git
In any case, when setting this all up I get a 500 internal server response with the following in the Apache error log:
[time] [error] [client *ip address*] Premature end of script headers: osqa.fcgi
Something I need to update?
Hi,
How can i install in my local wamp server ?
Please help.