Skip to content
ryanbriones edited this page Dec 12, 2012 · 2 revisions

These are my notes for creating a working Adopt-a-Sidewalk server on EC2. It uses Ubuntu 12.04.1 (current, recommended Ubuntu AMI). The checkinstall command produces a .dpkg file that could be reused to install postgis (and other packages not in Ubuntu's repo) quicker. So if you create multiple machines using this setup, reuse those.

Replace ec2-23-20-234-224.compute-1.amazonaws.com (in all instances) with the hostname of the EC2 instance you're working with.

$ ssh -i adoptasidewalk.pem ubuntu@ec2-23-20-234-224.compute-1.amazonaws.com
$ sudo apt-get update
$ sudo apt-get -y install build-essential git-core openssl libreadline6 libreadline6-dev curl zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config checkinstall postgresql postgresql-server-dev-9.1 libjson0-dev libproj-dev python2.7-dev swig apache2-prefork-dev libapr1-dev libaprutil1-dev libcurl4-openssl-dev unzip
$ curl -O http://download.osgeo.org/geos/geos-3.3.5.tar.bz2
$ tar jxvf geos-3.3.5.tar.bz2
$ cd geos-3.3.5
$ ./configure --enable-python
$ make -j2
$ sudo checkinstall -y --nodoc
$ cd ~
$ curl -O http://download.osgeo.org/gdal/gdal-1.9.1.tar.gz
$ tar zxvf gdal-1.9.1.tar.gz
$ cd gdal-1.9.1
$ ./configure --with-python --with-pg=/usr/lib/postgresql/9.1/bin/pg_config
$ make -j2
$ sudo checkinstall -y --nodoc
$ cd ~
$ curl -O http://download.osgeo.org/proj/proj-4.8.0.tar.gz
$ tar zxvf proj-4.8.0.tar.gz
$ cd proj-4.8.0
$ ./configure
$ make -j2
$ sudo checkinstall -y --nodoc
$ cd ~
$ curl -O http://www.postgis.org/download/postgis-2.0.1.tar.gz
$ tar zxvf postgis-2.0.1.tar.gz
$ cd postgis-2.0.1
$ ./configure
$ make -j2
$ vim postinstall-pak

post-install-pak:

ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql
ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp
$ vim postremove-pak

postremove-pak:

/usr/local/bin/shp2pgsql
/usr/local/bin/pgsql2shp
$ sudo checkinstall -y --nodoc
$ sudo ldconfig
$ sudo useradd -G admin -m -b /home -s /bin/bash adopt
$ sudo -u postgres createuser -s -d -R adopt
$ sudo su - adopt
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh
$ vim authorized_keys

Insert your SSH Public Key

$ chmod 600 authorized_keys
$ exit
$ sudo visudo

Change

%admin ALL=(ALL) ALL

To

%admin ALL=NOPASSWD: ALL

So you can run sudo commands as the adopt user without using a password

$ exit
$ ssh adopt@ec2-23-20-234-224.compute-1.amazonaws.com
$ sudo curl -L https://get.rvm.io | sudo bash -s stable
$ sudo adduser adopt rvm
$ exit
ssh adopt@ec2-23-20-234-224.compute-1.amazonaws.com
$ rvm install 1.9.3
$ rvm use --default 1.9.3
$ gem install passenger
$ passenger-install-apache2-module
$ sudo vim /etc/apache2/conf.d/passenger

Fill this with the Apache configuration lines passenger-install-apache2-module instructs you to add

$ cd ~
$ curl -L https://data.cityofchicago.org/download/77cn-6x4c/application/zip >chicagosidewalks.zip
$ unzip chicagosidewalks.zip
$ shp2pgsql -s 3435:4326 -g the_geom -I chicagosidewalks.shp >chicagosidewalks.sql
$ createdb adoptasidewalk_production
$ psql adoptasidewalk_production -c "CREATE EXTENSION postgis;"
$ cd ~
$ git clone https://github.com/cfachicago/adopt-a-sidewalk.git
$ cd adopt-a-sidewalk
$ vim config/database.yml

config/database.yml

production:
  adapter: postgresql
  database: adoptasidewalk_production
  username: adopt
$ bundle
$ rake db:migrate RAILS_ENV=production GMAPS_KML_ENDPOINT=foo
$ vim /etc/apache2/sites-available/adoptasidewalk

sites-available/adoptasidewalk

<VirtualHost *:80>
  DocumentRoot /home/adopt/adopt-a-sidewalk/public
  SetEnv GMAPS_KML_ENDPOINT ec2-23-20-234-224.compute-1.amazonaws.com
</VirtualHost>
$ sudo a2ensite adoptasidewalk
$ sudo a2dissite default
$ sudo service apache2 reload
Clone this wiki locally