goliathdrakken

# May 04 2011 - 8:05 PM

I've been running the frontend of my kegbot install on Dreamhost for sometime now. I thought I would post some instructions on how I set this up in case others were interested. Just a little background on my setup. I have a linux machine that is hooked up locally at my kegerator, it uses the latest repository tip of the pykeg software. I have pykeg setup to use a MySQL database, this database exists on my dreamhost server. This allows me to source this data from anywhere with an internet connection. I then have the pykeg package installed on one of my Dreamhost subdomains. This ensures that my kegweb is always available, even if I take my local kegerator offline. Outlined below is the process I used to setup pykeg on my Dreamhost account. This will probably work with other shared hosting services as well.

1. Setup a new sub/domain with the following settings (DH Panel)
- Check: Passenger (Ruby/Python apps only)
- Make sure that "/public" was appended to the web directory
- It is reccomended to create a new user for this site, the user requires shell access

2. Connect to your host using ssh

3. Download and install python 2.6.6
cd ~
mkdir tmp
cd tmp
wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -xzvf Python-2.6.6.tgz
cd Python-2.6.6
./configure --prefix=$HOME
make
make install


4. Add local directories to PATH
-Add the following lines to .bash_profile
export PATH="$HOME/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/lib/"

-Load the updated profile
source ~/.bash_profile

-Confirm that the localy installed python is first in the path
which python


5. Get Kegbot source
You can also push your local pykeg source to your own repository so that your remote Dreamhost install always has the same changes as your local install. In that case, clone your repo instead of the one below.
cd ~
hg clone https://kegbot.googlecode.com/hg/ kegbot


6. Install Kegbot in develop mode
cd ~/kegbot/pykeg
python setup.py develop


7. Setup configuration files
mkdir ~/.kegbot
cp ~/kegbot/pykeg/common_settings.py.example ~/.kegbot/common_settings.py


Make the following changes to ~/.kegbot/common_settings.py
-Complete the database settings to match your mysql server
-Set timezone
-Set MEDIA_ROOT='/home/USERNAME/kegbot/pykeg/src/pykeg/web/media/'
-Alter the secret key from the default
-Set the admin name/email
-Set TEMPLATE_DIR='/home/USERNAME/kegbot/pykeg/src/pykeg/web/templates/'

8. Copy kegweb.wsgi to web directory
cp ~/kegbot/pykeg/kegweb.wsgi ~/SITENAME/passenger_wsgi.py

Be sure the file is named passenger_wsgi.py as the Dreamhost Apache settings look for this specific file.

9. Edit passenger_wsgi.py
-Remove shebang line (#!/usr/bin/env python)
-Add following lines after import statement
INTERP = "/home/USERNAME/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

-Set Virtual Env
VIRTUAL_ENV = '/home/USERNAME'


10. Setup symlinks
cd ~/SITENAME/public
ln -s /home/USERNAME/lib/python2.6/site-packages/Django-1.2.5-py2.6.egg/django/contrib/admin/media admin_media

(Note: the Django directory may be different based on version downloaded)
ln -s /home/USERNAME/kegbot/pykeg/src/pykeg/web/media/ media


11. Add restart file
mkdir ~/SITENAME/tmp
touch ~/SITENAME/tmp/restart.txt


If all worked out you should have a functioning kegweb install on your Dreamhost account.
My Kegbot on Dreamhost




bender

# May 05 2011 - 10:05 PM

Hi goliath,

This is a great tutorial, and I am looking to get this set up. However, I ran into an issue with it. I completed all the steps(I think correctly) but am getting the following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@kegbot.michaelpbender.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.


The http logs don't show much, just:


[Thu May 05 22:38:29 2011] [error] [client 97.102.238.81] Premature end of script headers:
[Thu May 05 22:38:29 2011] [error] [client 97.102.238.81] Premature end of script headers: internal_error.html
[Thu May 05 22:40:11 2011] [error] [client 97.102.238.81] Premature end of script headers:
[Thu May 05 22:40:11 2011] [error] [client 97.102.238.81] Premature end of script headers: internal_error.html
[Thu May 05 22:44:15 2011] [error] [client 97.102.238.81] Premature end of script headers:
[Thu May 05 22:44:15 2011] [error] [client 97.102.238.81] Premature end of script headers: internal_error.html

Any ideas?





goliathdrakken

# May 05 2011 - 11:05 PM

I remember seeing a similar error to this once, I'm working on trying to duplicate it so I can remember what caused it and how to fix it.

In the mean time can you provide me with a listing of your env variables using the env command, and a copy of your passenger_wsgi.py file so I can look for the obvious problems.




goliathdrakken

# May 06 2011 - 1:05 AM

Ok this has got me stumped now. I used these steps to setup my host originally, many months ago. Now I am trying to setup a new test one and I am getting the same errors. I found a few things that needed adjusted, and still errors. I'm at the point now where I've copied over all my config files from the host that is functioning and it still isn't working. Apparently Dreamhost just doesn't want to make things easy now. I'll post back with updated instructions once I work out this new bug.




bender

# May 06 2011 - 9:05 AM

Thanks goliath, from what I read PHP CGI may be a culprit. I'm going to try changing this for my sub domain and see if it does the trick:

Change from PHP 5 FASTCGI to PHP 5 CGI




bender

# May 06 2011 - 9:05 AM

That didn't work.

I also had a question about the database settings in common_settings.py. In the old version you can specify the host an port. In the new version there doesn't seem to be a space for it. How did you accomplish this? Can I just add

'HOST' : 'sql.example.com',
'PORT': '35123', (example)

OLD:
# Other databases ('postgresql', 'mysql', or 'ado_mssql')
#DATABASE_ENGINE = 'mysql'
#DATABASE_NAME = 'kegbot'
#DATABASE_USER = 'kegbot_user'
#DATABASE_PASSWORD = 'kegbot_password'
#DATABASE_HOST = '' # Set to empty string for localhost.
#DATABASE_PORT = '' # Set to empty string for default port.

New:


# Example MYSQL settings (rename to 'default' to use)
'example_mysql' : {
'NAME' : 'kegbot',
'ENGINE' : 'django.db.backends.mysql',
'USER' : 'kegbot_user',
'PASSWORD': 'kegbot_password',
},





bender

# May 06 2011 - 9:05 AM

Oh, and I forgot to add, a differnet Django version was installed for me. So I had to change the one step to this:


ln -s /home/USERNAME/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/contrib/admin/media admin_media





bender

# May 06 2011 - 8:05 PM

This is driving me nuts! I have been trying to figure out what the issue is all day. I have unsuccessfully tried 100 different changes. The problem with using passenger on dreamhost is that you don't get to see the django error messages, just the Internal server error message.




goliathdrakken

# May 08 2011 - 10:05 PM

I've been out of town for the weekend. I'll re-investigate this some more tomorrow. I'm in the process of comparing my functioning install vs the new install to find the difference that is causing the error.




bender

# May 09 2011 - 10:05 AM

Edit - See latest post

Edited by bender (May 9, 2011 22:06:04)