3 # This script sets up a Nominatim installation on a Ubuntu box.
 
   5 # For more detailed installation instructions see also
 
   6 # http://wiki.openstreetmap.org/wiki/Nominatim/Installation
 
   8 ## Part 1: System preparation
 
  10 ## During 'vagrant provision' this script runs as root and the current
 
  11 ## directory is '/root'
 
  15 ### maybe create ubuntu user
 
  18 # if [[ ! `id -u $USERNAME` ]]; then
 
  19 #   useradd $USERNAME --create-home --shell /bin/bash
 
  22 #   echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-$USERNAME-user
 
  23 #   chmod 0440 /etc/sudoers.d/99-$USERNAME-user
 
  24 #   service sudo restart
 
  26 #   # add basic .profile
 
  27 #   cp -r .ssh .profile .bashrc /home/$USERNAME/
 
  28 #   chown -R $USERNAME /home/$USERNAME/.*
 
  29 #   chgrp -R $USERNAME /home/$USERNAME/.*
 
  31 #   # now ideally login as $USERNAME and continue
 
  36 sudo apt-get update -qq
 
  37 sudo apt-get upgrade -y
 
  38 sudo apt-get install -y build-essential libgeos-dev libpq-dev libbz2-dev \
 
  39                         libtool automake libproj-dev libboost-dev  libboost-system-dev \
 
  40                         libboost-filesystem-dev libboost-thread-dev libexpat-dev
 
  41 sudo apt-get autoremove -y
 
  43 # get arrow-keys working in terminal (e.g. editing in vi)
 
  44 echo 'stty sane' >> ~/.bash_profile
 
  45 echo 'export TERM=linux' >> ~/.bash_profile
 
  46 source ~/.bash_profile
 
  50 ### PostgreSQL 9.3 + PostGIS 2.1
 
  53 sudo apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib-9.3 postgresql-server-dev-9.3 
 
  54 # already included: proj-bin libgeos-dev
 
  56 # make sure OS-authenticated users (e.g. $USERNAME) can access
 
  57 sudo sed -i "s/ident/trust/" /etc/postgresql/9.3/main/pg_hba.conf
 
  58 sudo sed -i "s/md5/trust/"   /etc/postgresql/9.3/main/pg_hba.conf
 
  59 sudo sed -i "s/peer/trust/"  /etc/postgresql/9.3/main/pg_hba.conf
 
  60 sudo /etc/init.d/postgresql restart
 
  63 sudo -u postgres createuser -s $USERNAME
 
  70 sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
 
  71 sudo apt-get update -qq
 
  72 sudo apt-get install -y apache2
 
  73 sudo apt-get install -y php7.0 php7.0-pgsql php7.0-fpm libapache2-mod-php7.0 php-pear php-db
 
  76 # get rid of some warning
 
  77 # where is the ini file? 'php --ini'
 
  78 echo "date.timezone = 'Etc/UTC'" | sudo tee /etc/php/7.0/cli/conf.d/99-timezone.ini > /dev/null
 
  85 sudo apt-get install -y libgeos-c1 libgeos++-dev libxml2-dev
 
  87 ## Part 2: Nominatim installaion
 
  89 # now ideally login as $USERNAME and continue
 
  92 # If the Nominatim source is not being shared with the host, check out source.
 
  93 if [ ! -d "Nominatim" ]; then
 
  94   sudo apt-get install -y git
 
  95   sudo -u $USERNAME git clone --recursive https://github.com/twain47/Nominatim.git
 
 100 sudo -u $USERNAME ./autogen.sh
 
 101 sudo -u $USERNAME ./configure
 
 102 sudo -u $USERNAME make
 
 107 LOCALSETTINGS_FILE='settings/local.php'
 
 108 if [[ -e "$LOCALSETTINGS_FILE" ]]; then
 
 109   echo "$LOCALSETTINGS_FILE already exist, writing to settings/local-vagrant.php instead."
 
 110   LOCALSETTINGS_FILE='settings/local-vagrant.php'
 
 113 # IP=`curl -s http://bot.whatismyipaddress.com`
 
 117    @define('CONST_Database_DSN', 'pgsql://@/nominatim');
 
 119    @define('CONST_Postgresql_Version', '9.3');
 
 120    @define('CONST_Postgis_Version', '2.1');
 
 122    @define('CONST_Website_BaseURL', 'http://$IP:8089/nominatim/');
 
 123 " > $LOCALSETTINGS_FILE
 
 132 ### Setup Apache/website
 
 135 sudo -u postgres createuser -SDR www-data
 
 140     # DirectoryIndex index.html
 
 141     # ErrorDocument 403 /index.html
 
 143     DocumentRoot "/var/www/"
 
 145     <Directory "/var/www/nominatim/">
 
 146       Options FollowSymLinks MultiViews
 
 147       AddType text/html   .php     
 
 150 ' | sudo tee /etc/apache2/sites-enabled/nominatim.conf > /dev/null
 
 153 service apache2 graceful
 
 156 mkdir -m 755 /var/www/nominatim
 
 157 chown $USERNAME /var/www/nominatim
 
 158 sudo -u $USERNAME ./utils/setup.php --create-website /var/www/nominatim
 
 161 # if you get 'permission denied for relation word', then try
 
 162 # GRANT usage ON SCHEMA public TO "www-data";
 
 163 # GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
 
 166 ## Test suite (Python)
 
 167 ## https://github.com/twain47/Nominatim/tree/master/tests
 
 169 apt-get install -y python-dev python-pip python-Levenshtein python-shapely \
 
 170                         python-psycopg2 tidy python-nose python-tidylib
 
 171 pip install certifi # deals with "SNI extension to TLS is not available" warning
 
 172 pip install lettuce==0.2.18 six==1.7 haversine
 
 173 pip install --upgrade pip setuptools
 
 176 ## https://github.com/twain47/Nominatim/tree/master/tests-php
 
 177 wget --quiet https://phar.phpunit.de/phpunit.phar
 
 178 chmod +x phpunit.phar
 
 179 mv phpunit.phar /usr/local/bin/phpunit