Skip to content

Install Process on Ubuntu 12.04

andrewbt edited this page Sep 4, 2012 · 26 revisions

Installing OpenTreeMap stack on a fresh Ubuntu 12.04 box.

This is a work in progress.

Install Packages via apt package manager:

Update your 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 currently necessary to get django_reputation
apt-get install python-pip

Install a variety of other required Python libs

The python setup.py install lines below may need sudo.

mkdir ~/libs

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

cd ~/libs
wget -O django-profiles.tar.gz https://bitbucket.org/ubernostrum/django-profiles/get/tip.tar.gz
tar xzf django-profiles.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
cd Unidecode-0.04.5
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
# @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
# @FIX: updated to 11.12. Should we just install via pip in the first place?
pip install --upgrade sorl-thumbnail

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 -O django-badges.tar.gz https://bitbucket.org/jiaaro/django-badges/get/tip.tar.gz
tar xzf django-badges.tar.gz
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

# @FIX: installing south was not listed in the docs
pip install south

# OPTIONAL: Install python-omgeo the Oatmeal Geocoder
cd ~/libs
git clone https://github.com/azavea/python-omgeo.git
cd python-omgeo
python setup.py build
python setup.py install

Fix PROJ.4 to deal with Spherical Mercator

cd ~/libs
wget http://download.osgeo.org/proj/proj-datumgrid-1.4.tar.gz
mkdir proj-datumgrid-1.4
tar xzf proj-datumgrid-1.4.tar.gz -C proj-datumgrid-1.4
cd proj-datumgrid-1.4
nad2bin null < null.lla
sudo cp null /usr/share/proj

Install django-shapes, first removing HttpResponse call

cd ~/libs
wget -O django-shapes.tar.gz https://bitbucket.org/springmeyer/django-shapes/get/tip.tar.gz
tar xzf django-shapes.tar.gz
cd springmeyer-django-shapes-f3c93240c56e

In shapes/views/export.py in the zip_response() method, comment out lines 117-123 and instead, return zip_stream.

It should look like this:

        # Stick it all in a django HttpResponse
        #response = HttpResponse()
        #response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')
        #response['Content-length'] = str(len(zip_stream))
        #response['Content-Type'] = mimetype
        #response.write(zip_stream)
        #return response

        return zip_stream

Then install.

python setup.py build
python setup.py install

Install django-reputation with a fix

cd ~/libs
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

Now we change default config and user because of a bug where 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 models.py, make the following changes:

    ....
    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
    ...

Install 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

May need sudo.

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

Set up Database

Create Create PostGIS database template

(Mostly via https://gist.github.com/1481128) May need some sudos. Also, before running the ./ configure step, it may behoove you to run "sudo apt-get install postgresql-server-dev-9.1" (or whatever PG version we're up to when you read this).

apt-get install postgresql-contrib libpq-dev checkinstall proj libgeos-dev libxml2 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
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;"'

Set password [from postgres prompt]

sudo -u postgres psql postgres
\password postgres

CTRL-D to exit postgres prompt.

Create a database using the template.

sudo -u postgres createdb -T template_postgis YOURDBNAME

Import Choices.sql into the database.

(andrewbt note: this may be deprecated/unnecessary in v1.2, need to double check)

sudo -u postgres psql YOURDBNAME -f Choices.sql

Enable non-peer login with postgres.

We're going to have the app identify itself as the main 'postgres' user, which is pretty rudimentary and somewhat unsafe.

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

Set up your settings_YOURLOCATION.py file.

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

Add to settings.py, before 'OTM_VERSION = "1.2"' :

    from settings_YOURLOCATION import *

Change DATABASES definition with db credentials:

    DATABASES = {
        'default': {
            'NAME': 'YOURDBNAME',
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'USER': 'postgres',
            'HOST': '',
            'PASSWORD': 'YOURDBPASSWORD',
            'PORT': '5432',
        }
    }

Set up your choices_LOCATION.py file.

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
python manage.py migrate

If you get errors

Put this in your local_settings.py, just to start:

ADD_FORM_TARGETS = [
('addsame', 'Add another tree using the same details'),
('add', 'Add another tree with new details'),
('edit','Continue editing this tree'),
('view', 'I\'m finished'),
]
ADD_FORM_TARGETS_DEFAULT = 'view'
API_KEY_GOOGLE_MAPS = ''
API_KEY_GOOGLE_ANALYTICS = ''

Get a template to start with, like this directory: https://github.com/jlivni/OpenTreeMap/tree/master/templates/Oakland