3 # hacks for broken vagrant box      #DOCS:
 
   4 sudo rm -f /var/lib/dpkg/lock       #DOCS:
 
   5 export APT_LISTCHANGES_FRONTEND=none #DOCS:
 
   6 export DEBIAN_FRONTEND=noninteractive #DOCS:
 
   9 # *Note:* these installation instructions are also available in executable
 
  10 #         form for use with vagrant under vagrant/Install-on-Ubuntu-18.sh.
 
  12 # Installing the Required Software
 
  13 # ================================
 
  15 # These instructions expect that you have a freshly installed Ubuntu 18.04.
 
  17 # Make sure all packages are up-to-date by running:
 
  22 # Now you can install all packages needed for Nominatim:
 
  24     sudo apt install -y php-cgi
 
  25     sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
 
  26                         libboost-filesystem-dev libexpat1-dev zlib1g-dev\
 
  27                         libbz2-dev libpq-dev libproj-dev \
 
  28                         postgresql-server-dev-10 postgresql-10-postgis-2.4 \
 
  29                         postgresql-contrib-10 postgresql-10-postgis-scripts \
 
  30                         php php-pgsql php-intl libicu-dev python3-pip \
 
  31                         python3-psutil python3-jinja2 python3-icu git
 
  33 # Some of the Python packages that come with Ubuntu 18.04 are too old, so
 
  34 # install the latest version from pip:
 
  36     pip3 install --user python-dotenv datrie pyyaml psycopg2-binary
 
  39 # System Configuration
 
  40 # ====================
 
  42 # The following steps are meant to configure a fresh Ubuntu installation
 
  43 # for use with Nominatim. You may skip some of the steps if you have your
 
  44 # OS already configured.
 
  46 # Creating Dedicated User Accounts
 
  47 # --------------------------------
 
  49 # Nominatim will run as a global service on your machine. It is therefore
 
  50 # best to install it under its own separate user account. In the following
 
  51 # we assume this user is called nominatim and the installation will be in
 
  52 # /srv/nominatim. To create the user and directory run:
 
  54 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
 
  56 # You may find a more suitable location if you wish.
 
  58 # To be able to copy and paste instructions from this manual, export
 
  59 # user name and home directory now like this:
 
  61 if [ "x$USERNAME" == "x" ]; then   #DOCS:
 
  62     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
 
  63     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
 
  66 # **Never, ever run the installation as a root user.** You have been warned.
 
  68 # Make sure that system servers can read from the home directory:
 
  72 # Setting up PostgreSQL
 
  73 # ---------------------
 
  75 # Tune the postgresql configuration, which is located in 
 
  76 # `/etc/postgresql/10/main/postgresql.conf`. See section *Postgres Tuning* in
 
  77 # [the installation page](../admin/Installation.md#postgresql-tuning)
 
  78 # for the parameters to change.
 
  80 # Restart the postgresql service after updating this config file.
 
  82 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
 
  83     sudo pg_ctlcluster 10 main start  #DOCS:
 
  85     sudo systemctl restart postgresql
 
  89 # Finally, we need to add two postgres users: one for the user that does
 
  90 # the import and another for the webserver which should access the database
 
  94     sudo -u postgres createuser -s $USERNAME
 
  95     sudo -u postgres createuser www-data
 
  98 # Installing Nominatim
 
  99 # ====================
 
 101 # Building and Configuration
 
 102 # --------------------------
 
 104 # Get the source code from Github and change into the source directory
 
 106 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
 
 108     git clone --recursive git://github.com/openstreetmap/Nominatim.git
 
 111     cd $USERHOME/Nominatim         #DOCS:
 
 114 # When installing the latest source from github, you also need to
 
 115 # download the country grid:
 
 117 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
 
 118     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
 
 121 # The code must be built in a separate directory. Create this directory,
 
 122 # then configure and build Nominatim in there:
 
 124     mkdir $USERHOME/build
 
 126     cmake $USERHOME/Nominatim
 
 131 # Nominatim is now ready to use. You can continue with
 
 132 # [importing a database from OSM data](../admin/Import.md). If you want to set up
 
 133 # a webserver first, continue reading.
 
 135 # Setting up a webserver
 
 136 # ======================
 
 138 # The webserver should serve the php scripts from the website directory of your
 
 139 # [project directory](../admin/Import.md#creating-the-project-directory).
 
 140 # This directory needs to exist when being configured.
 
 141 # Therefore set up a project directory and create the website directory:
 
 143     mkdir $USERHOME/nominatim-project
 
 144     mkdir $USERHOME/nominatim-project/website
 
 146 # The import process will populate the directory later.
 
 148 # Option 1: Using Apache
 
 149 # ----------------------
 
 151 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
 
 153 # Apache has a PHP module that can be used to serve Nominatim. To install them
 
 156     sudo apt install -y apache2 libapache2-mod-php
 
 158 # You need to create an alias to the website directory in your apache
 
 159 # configuration. Add a separate nominatim configuration to your webserver:
 
 162 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
 
 163 <Directory "$USERHOME/nominatim-project/website">
 
 164   Options FollowSymLinks MultiViews
 
 165   AddType text/html   .php
 
 166   DirectoryIndex search.php
 
 170 Alias /nominatim $USERHOME/nominatim-project/website
 
 175 # Then enable the configuration with
 
 178     sudo a2enconf nominatim
 
 180 # and restart apache:
 
 182 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
 
 183     sudo apache2ctl start             #DOCS:
 
 185     sudo systemctl restart apache2
 
 188 # The Nominatim API is now available at `http://localhost/nominatim/`.
 
 193 # Option 2: Using nginx
 
 194 # ---------------------
 
 196 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
 
 198 # Nginx has no native support for php scripts. You need to set up php-fpm for
 
 199 # this purpose. First install nginx and php-fpm:
 
 201     sudo apt install -y nginx php-fpm
 
 203 # You need to configure php-fpm to listen on a Unix socket.
 
 206 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
 
 208 ; Replace the tcp listener and add the unix socket
 
 209 listen = /var/run/php7.2-fpm.sock
 
 211 ; Ensure that the daemon runs as the correct user
 
 212 listen.owner = www-data
 
 213 listen.group = www-data
 
 216 ; Unix user of FPM processes
 
 220 ; Choose process manager type (static, dynamic, ondemand)
 
 226 # Then create a Nginx configuration to forward http requests to that socket.
 
 229 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
 
 231     listen 80 default_server;
 
 232     listen [::]:80 default_server;
 
 234     root $USERHOME/nominatim-project/website;
 
 235     index search.php index.html;
 
 237         try_files \$uri \$uri/ @php;
 
 241         fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
 
 242         fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
 
 243         fastcgi_param QUERY_STRING    \$args;
 
 244         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
 
 245         fastcgi_index index.php;
 
 246         include fastcgi_params;
 
 249     location ~ [^/]\.php(/|$) {
 
 250         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 
 251         if (!-f \$document_root\$fastcgi_script_name) {
 
 254         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
 
 255         fastcgi_index search.php;
 
 256         include fastcgi.conf;
 
 263 # Enable the configuration and restart Nginx
 
 266 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
 
 267     sudo /usr/sbin/php-fpm7.2 --nodaemonize --fpm-config /etc/php/7.2/fpm/php-fpm.conf & #DOCS:
 
 268     sudo /usr/sbin/nginx &            #DOCS:
 
 270     sudo systemctl restart php7.2-fpm nginx
 
 273 # The Nominatim API is now available at `http://localhost/`.