Skip to content

Install Process on Ubuntu 12.04

jeffschuler edited this page Aug 27, 2012 · 26 revisions

I've been keeping notes on my process of installing the OpenTreeMap stack on an Ubuntu 12.04 AMI. This is a work in progress.

# -----------------
# Packages
# -----------------

# Update packaging info
apt-get update

# Apache and PostgreSQL
apt-get install apache2
apt-get install postgresql
apt-get install postgis

# Required libs
apt-get install python-django
apt-get install libapache2-mod-wsgi
apt-get install python-psycopg2
apt-get install binutils
apt-get install libgeos-3.2.2      # 3.2.0 on 11.04 Natty
apt-get install libgeos-c1         # @FIX: c1 instead of cl
apt-get install libgdal1-1.7.0     # 1.6.0 on 11.04 Natty
apt-get install libproj0
apt-get install python-django-tagging
apt-get install python-imaging
apt-get install python-xlrd
apt-get install python-feedparser
apt-get install python-memcache
apt-get install python-beautifulsoup
apt-get install python-django-debug-toolbar
apt-get install python-simplejson
apt-get install python-django-extensions
apt-get install python-django-threadedcomments  # @FIX: add this
apt-get install python-gdal
apt-get install gdal-bin

# Other necessities
apt-get install git
apt-get install subversion # Really only necessary here to get django_reputation
apt-get install python-pip


# -----------------
# Python Libs
# -----------------

mkdir ~/libs

cd ~/libs
tar xzf template_utils-0.4p2.tar.gz
wget http://django-template-utils.googlecode.com/files/template_utils-0.4p2.tar.gz
template_utils-0.4p2
python setup.py build
python setup.py install

cd ~/libs
wget https://bitbucket.org/ubernostrum/django-profiles/get/tip.tar.gz
tar xzf tip.tar.gz
cd ubernostrum-django-profiles-c21962558420
python setup.py build
python setup.py install

cd ~/libs
wget http://pypi.python.org/packages/source/U/Unidecode/Unidecode-0.04.5.tar.gz
tar xzf Unidecode-0.04.5.tar.gz
python setup.py build
python setup.py install

cd ~/libs
wget http://geopy.googlecode.com/files/geopy-0.94.tar.gz
tar xzf geopy-0.94.tar.gz
cd geopy-0.94
python setup.py build
python setup.py install

cd ~/libs
wget http://django-pagination.googlecode.com/files/django-pagination-1.0.5.tar.gz
tar xzf django-pagination-1.0.5.tar.gz
cd django-pagination-1.0.5
python setup.py build
python setup.py install

cd ~/libs
wget https://bitbucket.org/springmeyer/django-shapes/get/tip.tar.gz
tar xzf tip.tar.gz.1
cd springmeyer-django-shapes-f3c93240c56e
python setup.py build
python setup.py install

cd ~/libs
# @FIX: the URL listed gives a 404
wget http://pypi.python.org/packages/source/s/sorl-thumbnail/sorl-thumbnail-3.2.5.tar.gz
tar xzf sorl-thumbnail-3.2.5.tar.gz
cd sorl-thumbnail-3.2.5
python setup.py build
python setup.py install

cd ~/libs
wget http://sourceforge.net/projects/dbfpy/files/dbfpy/2.2.5/dbfpy-2.2.5.tar.gz
tar xzf dbfpy-2.2.5.tar.gz
cd dbfpy-2.2.5
python setup.py build
python setup.py install

cd ~/libs
wget https://bitbucket.org/jiaaro/django-badges/get/tip.tar.gz
tar xzf tip.tar.gz.2
cd jiaaro-django-badges-07526b7f7d6f
python setup.py build
python setup.py install

cd ~/libs
wget https://bitbucket.org/ubernostrum/django-registration/downloads/django-registration-0.8-alpha-1.tar.gz
tar xzf django-registration-0.8-alpha-1.tar.gz
cd django-registration-0.8-alpha-1
python setup.py build
python setup.py install

cd ~/libs
git clone git://github.com/miracle2k/webassets.git
cd webassets
python setup.py build
python setup.py install

pip install django-pipeline

pip install south # @FIX: this was not listed


# -----------------
# django-reputation with fix
# -----------------
svn checkout http://django-reputation.googlecode.com/svn/trunk/ django-reputation
cd django-reputation
sudo cp django_reputation -R /usr/local/lib/python2.7/dist-packages/django_reputation
# Change default config and user bug: (b/c it doesn't seem to accept values in settings.py)
cd /usr/local/lib/python2.7/dist-packages/django_reputation
# In config.py - <change values as needed>
# In model.py - change >
    ....
    relevant_reputation_actions = UserReputationAction.objects.filter(user=user).filter........
    ....
    if expected_delta <= MAX_REPUTATION_GAIN_PER_DAY and expected_delta >= -1 * MAX_REPUTATION_LOSS_PER_DAY:
        delta = action_value
    elif expected_delta > MAX_REPUTATION_GAIN_PER_DAY:
        delta = 0
    elif expected_delta < MAX_REPUTATION_LOSS_PER_DAY:
        delta = 0
    ...


# -----------------
# django-sorting with patch
# -----------------
cd ~/libs
git clone git://github.com/directeur/django-sorting.git
cd django-sorting
# Apply changes from https://github.com/directeur/django-sorting/issues#issue/8
# Using patch in gist:
git clone git://gist.github.com/3470505.git
mv 3470505/django_sorting-autosort-2.patch .
rm -rf 3470505
patch -p0 < django_sorting-autosort-2.patch
cp django_sorting -R /usr/local/lib/python2.7/dist-packages/django_sorting

# -----------------
# Get OpenTreeMap source
# -----------------

cd /var/www
git clone --branch v1.2 https://github.com/azavea/OpenTreeMap.git opentreemap


# -----------------
# Database
# -----------------

# Create PostGIS template
#  via https://gist.github.com/1481128
apt-get install postgresql-contrib libpq-dev checkinstall proj libgeos-dev libxml2 libxml2-dev libxml2-dev
sudo mkdir -p '/usr/share/postgresql/9.1/contrib/postgis-1.5'
cd /usr/share/postgresql/9.1/contrib/postgis-1.5
wget http://postgis.refractions.net/download/postgis-1.5.5.tar.gz
wget http://postgis.refractions.net/download/postgis-1.5.5.tar.gz
tar zxvf postgis-1.5.5.tar.gz && cd postgis-1.5.5/
./configure && sudo make && sudo checkinstall --pkgname postgis-1.5.5 --pkgversion 1.5.5-src --default
su postgres -c'createdb -E UTF8 -U postgres template_postgis'
su postgres -c'createlang -d template_postgis plpgsql;'
su postgres -c'psql -U postgres -d template_postgis -c "CREATE EXTENSION hstore;"'
su postgres -c'psql -U postgres -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql'
su postgres -c'psql -U postgres -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql'
su postgres -c'psql -U postgres -d template_postgis -c "select postgis_lib_version();"'
su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"'
su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"'
su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"'

sudo -u postgres psql postgres
# Set password
\password postgres
# CTRL-D to exit postgres prompt
# Create a database
sudo -u postgres createdb -T template_postgis opentree
# import Choices.sql
sudo -u postgres psql opentree -f Choices.sql

# Edit /etc/postgresql/9.1/main/pg_hba.conf and change:
    local   all             postgres                                peer
# to
    local   all             postgres                                md5

# Restart postgres
sudo service postgresql restart


# -----------------
# settings_LOCATION.py
# -----------------

# Get copies of other cities' settings_LOCATION.py files -- from https://github.com/jlivni/OpenTreeMap
# I copied Oakland's as settings_cleveland.py, and tweaked.

# add to settings.py, before 'OTM_VERSION = "1.2"' :
    from settings_cleveland import *

# change DATABASES definition with db credentials:
    DATABASES = {
        'default': {
            'NAME': 'opentree',
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'USER': 'postgres',
            'HOST': '',
            'PASSWORD': 'p0$7$qlg1$',
            'PORT': '5432',
        }
    }


# -----------------
# choices_LOCATION.py
# -----------------

cd /var/www/opentreemap
cp treemaps/choices.py choices_LOCATION.py
# add to settings.py:
    from choices_cle import *

# -----------------
# Run install script
# -----------------
cd /var/www/opentreemap
python manage.py syncdb