Installing OSQA on DreamHost

Be careful, this is an early draft
This is an early draft of the instructions for installing OSQA on DreamHost.
It may be incomplete and is not yet fully tested. It is a work-in-progress.

Introduction

DreamHost is a popular hosting provider, and OSQA is known to work well there. By following these instructions you should be able to have your new OSQA site up and running in approximately 30 minutes.

The DreamHost approach to hosting Django applications is somewhat novel, but it definitely works. They use a tool called Phusion Passenger to connect your Django/Python web application to their production Apache servers. Passenger is more often used for Ruby-on-Rails solutions, but it also seems to do quite well for Python and Django.

The instructions here are largely based on DreamHost's Django instructions as well as their instructions for Passenger WSGI.

IMPORTANT: Vote for a one-click installer
If you'd rather eliminate all this setup work, then vote for a DreamHost "one-click installer" for OSQA.

Step 1: Set up a shell account

If you don't already have a shell account set up for your domain, you will need to do so now. See Enabling Shell Access for details.

Step 2: Configure your domain

Next, you will need to set up your domain to use Passenger. You can do so by following these steps:

  1. Open the Manage Domains section of the panel, and start editing your domain.
  2. Scroll down to the "Users, Files, and Paths" section. If your web directory does not end with "/public", add that to your web directory.
  3. Once you have done so, scroll down to "Web Options". Turn on the "Passenger" checkbox.
    '''NOTE''': If you currently have files under the domain, you will need to move them into the new "public" directory to make them appear!

Step 3: Create a Python 2.5 "virtualenv"

OSQA runs best on Python 2.5 or greater. DreamHost currently defaults to Python 2.4, but Python 2.5 is also available, and we recommend you use it.

The easiest way to do this is to set up a "virtual environment" for Python using virtualenv. Virtualenv allows you to add and modify Python modules without access to the global installation. As of April 2010 1.4.8 is the latest, please check here for a newer version.

SSH into your server, and run these commands:

wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.4.8.tar.gz
tar xzf virtualenv-1.4.8.tar.gz
python2.5 virtualenv-1.4.8/virtualenv.py $HOME/local
rm -rf virtualenv*
export PATH=$HOME/local/bin:$PATH

When you login again later, you'll need to make sure your path gives preference to ~/local/bin before /usr/bin so that your "local" copy of Python runs, and that your scripts refer to that location. That's what the line "export PATH=$HOME/local/bin:$PATH" accomplishes. You may want to create .bashrc and/or .bash_profile files like the following (or add these lines to your existing files):

.bashrc
export PATH=$HOME/local/bin:$PATH
.bash_profile
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Now that you have configured virtualenv, you can run easy_install to install Python modules.

Step 4: Install the required Python libraries

OSQA depends on certain required Python libraries and uses others that we strongly recommend. In this section we will install these libraries into your DreamHost account. While still connected to your SSH terminal session, run these commands:

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

Step 5: Get the OSQA source code from subversion

You'll get the latest and greatest OSQA source code directly from the project's Subversion repository. It's pretty easy to do. While we're at it, we'll also make log and temporary directories writable. In the same SSH terminal session, run these commands:
(NOTE: replace "your_domain" with the domain name you created in Step 2 above)

svn co http://svn.osqa.net/svnroot/osqa/trunk/ ~/<your_domain>/osqa
chmod 777 ~/<your_domain>/osqa/tmp
chmod 777 ~/<your_domain>/osqa/log

Step 6: Create a database

Every OSQA site needs a database. If you don't have one prepared already, you can create one through the panel at MySQL Databases. We strongly recommend creating a database just for OSQA (rather than sharing a database with other applications), as OSQA does not use a prefix on its table names.

Step 7: Edit the Django settings file

Now you need to tell OSQA which database and which domain to use. In your SSH terminal window switch into your OSQA installation directory, copy the file settings_local.py.dist to settings_local.py, and then use pico or vim to edit it:

cd ~/<your_domain>/osqa
cp settings_local.py.dist settings_local.py
pico settings_local.py

Locate the section where database settings go, and complete it with the values you used above in Step 6 when creating the database. Here's an example:

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

A little below that section you'll find another setting named APP_URL. Complete it with your fully qualified domain, (eg - "http://www.my_domain.com".)
Save the file and exit the editor.

Step 8: Prepare the database for OSQA

Now it is time to create and populate the various database tables OSQA and Django need. Use your SSH terminal window to run these commands:

cd ~/<your_domain>/osqa
python manage.py syncdb --all
python manage.py migrate forum --fake

When prompted to create a new user, just say no.

Step 9: Create the passenger_wsgi.py file

Go one level up in the directory structure

cd ..

to the domain base folder and create a file named passenger_wsgi.py file with the following content:

passenger_wsgi.py
import sys, os
INTERP = "/home/<myusername>/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.append('/home/<myusername>/<your_domain>')
sys.path.append('/home/<myusername>/<your_domain>/osqa')
os.environ['DJANGO_SETTINGS_MODULE'] = "osqa.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
from paste.exceptions.errormiddleware import ErrorMiddleware
def testapplication(environ, start_response):
   status = '200 OK'
   output = 'Hello World! Running Python version ' + sys.version + '\n\n'
   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   # to test paste's error catching prowess, uncomment the following line
   # while this function is the "application"
   raise("error")
   start_response(status, response_headers)
   return [output]
application = ErrorMiddleware(application, debug=True)

Replace <myusername> with your shell account username and <your_domain> with your site domain name. Make sure that you have activated passenger on your account administration panel. You van now visit your domain and create your first user, which will be your superuser.

Step 10: Enjoy your new OSQA site!

If you have followed all the previous steps, then you should be proud to visit your domain's URL in your favorite web browser and see your new OSQA site up and running. If it is, congratulations and well done! If not, just retrace all your steps and be sure you didn't miss anything. Feel free to come visit us in the OSQA chat channel, and we'll be happy to try to help.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Feb 09, 2011

    Philip Ashlock says:

    Everything seems to work fine up to the passenger_wsgi.py file which seems as if...

    Everything seems to work fine up to the passenger_wsgi.py file which seems as if it may have some issues or maybe something else is throwing an error, but all have I have to debug with is "An error occurred importing your passenger_wsgi.py"

    1. Feb 09, 2011

      Philip Ashlock says:

      This seems to work as the passenger_wsgi.py file: import sys,os INTERP = "/ho...

      This seems to work as the passenger_wsgi.py file:

      import sys,os
      INTERP = "/home/<username>/local/bin/python"
      if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
      sys.path.append("/home/<username>/<your_domain>/")
      sys.path.append("/home/<username>/<your_domain>/osqa")
      os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
      import django.core.handlers.wsgi
      application = django.core.handlers.wsgi.WSGIHandler()
      1. Mar 08, 2011

        kristi says:

        Thanks, that worked for me. Also, to get email working using Dreamhost's smtp, ...

        Thanks, that worked for me.

        Also, to get email working using Dreamhost's smtp, I had to use the *.mail.dreamhost.com address for my domain. (I'm on sub3.mail.dreamhost.com for example). Using mail.mydomain.com didn't work for me.

        Running 'ping mail.mydomain.com' might find you which mail host to use (worked from my Ubuntu machine) or 'host mail.mydomain.com'. Or else you might need to find your mail.mydomain.com ip and run nslookup, as described in http://wiki.dreamhost.com/Certificate_Domain_Mismatch_Error

        Example email settings:

        Email server: sub3.mail.dreamhost.com
        Email port: 587
        Email user: user@mydomain.com
        Use TLS: [checked]

        1. Mar 17, 2011

          StatSpotting! says:

          I have some issues with tags on my site, tags are getting added but the taglist ...

          I have some issues with tags on my site, tags are getting added but the taglist shows as empty. and tag search returns nothing. Are there any known issues?

  2. Mar 27, 2011

    kristi says:

    Should add 'easy_install Paste' to step 4 for the wsgi file in step 9 to work.

    Should add 'easy_install Paste' to step 4 for the wsgi file in step 9 to work.

    1. Jul 18, 2011

      kristi says:

      Also in Step 4, the "easy_install django" command needs a -U flag easy_install -...

      Also in Step 4, the "easy_install django" command needs a -U flag
      easy_install -U django
      to force the upgrade of django from 1.2.1 to 1.3 or else you'll have errors running osqa (see http://meta.osqa.net/questions/8752/how-can-i-fix-this-server-error-when-installing-osqa-on-dreamhost?page=1#9584)

  3. Apr 29, 2011

    Steve Free says:

    On Step 8, when I run the commands: cd ~/<your_domain>/osqa python manage....

    On Step 8, when I run the commands:
    cd ~/<your_domain>/osqa
    python manage.py syncdb --all
    python manage.py migrate forum --fake

    I'm getting the following:

    Traceback (most recent call last):
      File "manage.py", line 4, in <module>
        import settings # Assumed to be in the same directory.
      File "/home/admin_answers/domain.com/osqa/settings.py", line 54, in <module>
        from settings_local import *
      File "/home/admin_answers/domain.com/osqa/settings_local.py", line 1
    *SyntaxError: encoding problem: with BOM*

    Any ideas?

    1. Jul 18, 2011

      kristi says:

      Looks like there were problems parsing your settings_local.py file. Check your ...

      Looks like there were problems parsing your settings_local.py file. Check your settings_local.py for syntax errors?

  4. Jul 18, 2011

    kristi says:

    Note that you can restart Passenger by touching the tmp/restart.txt file to...

    Note that you can restart Passenger by touching the tmp/restart.txt file

    touch ~/site.com/tmp/restart.txt

    http://wiki.dreamhost.com/Passenger

  5. Jul 27, 2011

    bruce says:

    Had a few clarifications. In step 2, it says to make sure you add /public to th...

    Had a few clarifications.

    In step 2, it says to make sure you add /public to the end of your domain. I think this is for Passenger compliance. In steps 5,7,8, and 9, it references <your_domain> as you set up in step two. Is <your_domain> /home/username/example.com or /home/username/example.com/public?

    Dreamhost has a Django setup script from (http://wiki.dreamhost.com/Django) Does this tutorial assume you have completed those tasks?

    In step 10, how do I check? Would I go to www.example.com/osqa/ ?

    Cheers
    bruce

    1. Jul 28, 2011

      kristi says:

      <your_domain> is example.com Example from step 5 chmod 777 ~/<your_d...

      <your_domain> is example.com

      Example from step 5
      chmod 777 ~/<your_domain>/osqa/tmp
      should be
      chmod 777 ~/example.com/osqa/tmp

      You do not have to run Dreamhost's Django script.

      Step 10: Go to your site: example.com

      You can configure osqa to be in a subdirectory at example.com/osqa, but by default it is not put in a subdirectory.

      1. Jul 28, 2011

        bruce says:

        Thank you kristi. I've got my site up and now can begin customization. Cheers

        Thank you kristi. I've got my site up and now can begin customization.

        Cheers

  6. Aug 08

    bruce says:

    Things are humming along nicely at dreamhost.com. I've been able to get a lot o...

    Things are humming along nicely at dreamhost.com. I've been able to get a lot of the themes/skins customized and even added a few pages to the registry.

    I've notice my search box in osqa doesn't work. Is this because of a choice Dreamhost makes on full text with MySQL? Is there something I can do?

    1. Aug 08

      kristi says:

      I was having search issues too. I had to run part of the forum_modules/mysqlful...

      I was having search issues too. I had to run part of the forum_modules/mysqlfulltext/fts_install.sql mysql scripts. See my answer at http://meta.osqa.net/questions/8198/why-search-engine-is-not-displaying-nothing-no-matter-what-keyword-i-enter/9820

      1. Aug 08

        bruce says:

        Right on target again Kristi. I covered your steps in meta.osqa.net and it work...

        Right on target again Kristi. I covered your steps in meta.osqa.net and it worked on Dreamhost. @Rick Ross/@Scott W, probably should add this to the recipe?