Skip to content
derekeder edited this page Mar 13, 2013 · 18 revisions

These instructions are based on http://imperialwicket.com/aws-configuring-a-geo-spatial-stack-in-amazon-linux (though we came across some issues along the way, documented here)

Install Postgresql

# install postgresql
sudo yum install postgresql postgresql-server postgresql-devel
sudo mkdir /usr/local/pgsql/
sudo mkdir /usr/local/pgsql/data
sudo chown postgres /usr/local/pgsql/data
sudo su postgres
initdb -D /usr/local/pgsql/data
postgres -D /usr/local/pgsql/data &
exit

Install PostGIS

This requires some build tools, and also the GEOS and PROJ libraries. On a Micro instance, making the GEOS and PROJ libraries will take a while (about 5-10 minutes), and drive your server load average to the 1.00-2.00 range. I'm going to unnecessarily change directories to what should be the current working directory a few times, just to make sure we're in the same place. After GEOS, PROJ, and PostGIS are built, we will also need to update our libraries, so the server knows where to find them.

sudo yum install gcc make gcc-c++ libtool libxml2-devel
# make a directory for building
cd /home/ec2-user/
mkdir postgis
cd postgis

# download, configure, make, install geos
wget http://download.osgeo.org/geos/geos-3.3.5.tar.bz2
tar xjf geos-3.3.5.tar.bz2
cd geos-3.3.5
./configure
make
sudo make install
   
# download, configure, make, install proj
cd /home/ec2-user/postgis/
wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
tar xzf proj-4.7.0.tar.gz
cd proj-4.7.0/nad
unzip ../../proj-datumgrid-1.5.zip
cd ..
./configure  
make
sudo make install

# download, configure, make, install postgis
cd /home/ec2-user/postgis/
wget http://postgis.refractions.net/download/postgis-1.5.6.tar.gz
tar xzf postgis-1.5.6.tar.gz 
cd postgis-1.5.6
./configure --with-geosconfig=/usr/local/bin/geos-config
make
sudo make install

# update your libraries
sudo su
echo /usr/local/lib >> /etc/ld.so.conf
exit
sudo ldconfig

Now that PostGIS is installed, we should create a template database for PostGIS. Anytime you are generating a new database that requires geospatial data, you can create it from this template.

The default sql scripts for setting up postGIS have some errors in them in postgis-1.5.2. See http://trac.osgeo.org/postgis/ticket/1820 and http://trac.osgeo.org/postgis/changeset/9735. The fix is to do a global replace in both sql files to replace 'C' with 'c' and 'SQL' with 'sql'.

# setup our postgis template
createdb -U postgres template_postgis
createlang -U postgres plpgsql template_postgis
psql -U postgres -d template_postgis -f /usr/share/pgsql/contrib/postgis-1.5/postgis.sql
psql -U postgres -d template_postgis -f /usr/share/pgsql/contrib/postgis-1.5/spatial_ref_sys.sql

Configure Apache and python using mod_wsgi

helpful docs: https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/

Install apache and mod_wsgi

sudo yum install httpd
supo yum install mod_wsgi

Edit your Apache config /etc/httpd/conf/httpd.conf

  Alias /robots.txt /var/www/html/councilmatic/councilmatic/static/robots.txt
  Alias /static/ /var/www/html/councilmatic/static/

  <Directory /var/www/html/councilmatic/static>
  Order deny,allow
  Allow from all
  </Directory>

  WSGIScriptAlias / /var/www/html/councilmatic/wsgi.py
  WSGIPythonPath /var/www/html/councilmatic/councilmatic:/var/www/html/councilmatic/.env/lib/python2.6/site-packages
  <Directory /var/www/html/councilmatic>
  <Files wsgi.py>
  Order deny,allow
  Allow from all
  </Files>
  </Directory>
sudo service httpd start
sudo service postgresql start

and navigate to the server in your browser

Fine tuning Django

SITE_ID

SITE_ID wasn't set for my install, so I had to set it manually. see: http://stackoverflow.com/questions/11814059/site-matching-query-does-not-exist/11814271#11814271

Email sending

in local_settings.py, comment out this line:

# Email
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

/Admins access

In the auth_users table, set the is_staff flag to 't' for any users you want to have admin access The default admin I created does not have permission to login to /admin. Need to fix this