HOWTO Install Kegbot on Dreamhost

From KegbotWiki

Jump to: navigation, search

Most of this guide is credited to goliathdrakken. Some additions and changes have been made by Bender.

This is a guide to install and run Kegweb and the Kegbot MYSQL database on your shared Dreamhost servers.


Contents

Setup a new sub/domain with the following settings (DH Panel)

Dreamhost Panel -> Domains -> Manage Domains -> Add New Domain/Sub Domain

  • Name -> Whatever you want, but I chose kegbot.mydomain.com
  • User -> Drop down to create new user (Best option - User will need shell access)
  • Web Directory -> mydomain.com/public
  • Check -> Extra Web Security
  • Check -> Passenger (Ruby/Python apps only)

Give User Shell Access

Dreamhost Panel -> Users -> Manage Users

  • Click edit for the user you created in step 1
  • Change user account type to shell

Set up your dreamhost database

Dreamhost Panel -> Goodies -> MYSQL Databases

  • Name your database
  • Pick a hostname or create one
  • Pick or choose a user for access to the database

Connect to your host using ssh

Download and install python 2.6.6

Instead of using virualenv and the shared version of Python on the DH servers, we are going to install our own version of Python that we have full control of. The commands below install Python to your home directory.

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

Add local directories to PATH

Adding the following paths to your profile ensures that every time you use python, the version from your home directory is used.

  • 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

Get Kegbot source

  • Clone the kegbot repository at github.com
cd ~
git clone git://github.com/Kegbot/kegbot.git

Install Kegbot

  • The stock kegbot software uses SQLite, since we are using MySQL the python-mysql package needs installed. PIL also needs installed, uncomment the packages in the setup.py file to ensure they are installed.
cd ~/kegbot/pykeg
vi setup.py
  • Uncomment the following lines:
#'MySQL-python',
#'pil',
  • Run a normal install:
python setup.py install
  • Or you can Install in develop mode
python setup.py develop

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/'

Copy kegweb.wsgi to web directory

Dreamhost looks for a wsgi file in your site directory, copy the kegweb.wsgi file there.

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.

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'

Setup symlinks

cd ~/SITENAME/public
ln -s /home/USERNAME/lib/python2.6/site-packages/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

Add restart file

To restart passenger, a restart file is used. Every time the time stamp on this file changes, passenger will restart the python services running the site. This is used every time you make changes to the kegbot code.

mkdir ~/SITENAME/tmp
touch ~/SITENAME/tmp/restart.txt

Build/Populate/Migrate the database

If this is your first install, run the following commands.

kegbot-admin.py kb_setup
kegbot-admin.py createsuperuser
kegbot-admin.py createcachetable cache

If you have kegbot set up already and have accumulated data, you will want to move it into the database. You can do this two ways.

If it is a dreamhost database, this can be easily done from the panel.

First export:

Dreamhost Panel -> Goodies -> MYSQL Databases

Click phpmyadmin on the hostname your database resides on. Log in. Click on your database on the left. Click on the export tab. Leave the defaults and choose save file as at the bottom. Click go.

Or from the command line on your own server use mysqldump

mysqldump -u root -p kegbot > kegbot.sql

Import:

Click phpmyadmin on the hostname your database resides on. Log in. Click on your database on the left. Click on the import tab. Click choose file. Leave the defaults and click go at the bottom. Click go.

Copy your media

If you have a previous install, you will want to copy over your images as well.

Go in to the /pykeg/src/pykeg/web/ folder in your previous install. Issue this command:

tar cvzf media.tgz media

Copy it to the same folder on your new install /home/USERNAME/kegbot/pykeg/src/pykeg/web/

Extract the contents:

tar -xvzf media.tgz
Personal tools