3 # hacks for broken vagrant box      #DOCS:
 
   4 sudo rm -f /var/lib/dpkg/lock       #DOCS:
 
   5 sudo update-locale LANG=en_US.UTF-8 #DOCS:
 
   6 export APT_LISTCHANGES_FRONTEND=none #DOCS:
 
   7 export DEBIAN_FRONTEND=noninteractive #DOCS:
 
  10 # *Note:* these installation instructions are also available in executable
 
  11 #         form for use with vagrant under vagrant/Install-on-Ubuntu-18.sh.
 
  13 # Installing the Required Software
 
  14 # ================================
 
  16 # These instructions expect that you have a freshly installed Ubuntu 18.04.
 
  18 # Make sure all packages are are up-to-date by running:
 
  21     sudo apt-get -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" --force-yes -fuy install grub-pc #DOCS:
 
  24 # Now you can install all packages needed for Nominatim:
 
  26     sudo apt install -y php-cgi
 
  27     sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
 
  28                         libboost-filesystem-dev libexpat1-dev zlib1g-dev\
 
  29                         libbz2-dev libpq-dev libproj-dev \
 
  30                         postgresql-server-dev-10 postgresql-10-postgis-2.4 \
 
  31                         postgresql-contrib-10 postgresql-10-postgis-scripts \
 
  32                         php php-pgsql php-intl php-symfony-dotenv \
 
  37 # System Configuration
 
  38 # ====================
 
  40 # The following steps are meant to configure a fresh Ubuntu installation
 
  41 # for use with Nominatim. You may skip some of the steps if you have your
 
  42 # OS already configured.
 
  44 # Creating Dedicated User Accounts
 
  45 # --------------------------------
 
  47 # Nominatim will run as a global service on your machine. It is therefore
 
  48 # best to install it under its own separate user account. In the following
 
  49 # we assume this user is called nominatim and the installation will be in
 
  50 # /srv/nominatim. To create the user and directory run:
 
  52 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
 
  54 # You may find a more suitable location if you wish.
 
  56 # To be able to copy and paste instructions from this manual, export
 
  57 # user name and home directory now like this:
 
  59     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
 
  60     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
 
  62 # **Never, ever run the installation as a root user.** You have been warned.
 
  64 # Make sure that system servers can read from the home directory:
 
  68 # Setting up PostgreSQL
 
  69 # ---------------------
 
  71 # Tune the postgresql configuration, which is located in 
 
  72 # `/etc/postgresql/10/main/postgresql.conf`. See section *Postgres Tuning* in
 
  73 # [the installation page](../admin/Installation.md#postgresql-tuning)
 
  74 # for the parameters to change.
 
  76 # Restart the postgresql service after updating this config file.
 
  78     sudo systemctl restart postgresql
 
  81 # Finally, we need to add two postgres users: one for the user that does
 
  82 # the import and another for the webserver which should access the database
 
  86     sudo -u postgres createuser -s $USERNAME
 
  87     sudo -u postgres createuser www-data
 
  90 # Installing Nominatim
 
  91 # ====================
 
  93 # Building and Configuration
 
  94 # --------------------------
 
  96 # Get the source code from Github and change into the source directory
 
  98 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
 
 100     git clone --recursive git://github.com/openstreetmap/Nominatim.git
 
 103     cd $USERHOME/Nominatim         #DOCS:
 
 106 # When installing the latest source from github, you also need to
 
 107 # download the country grid:
 
 109 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
 
 110     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
 
 113 # The code must be built in a separate directory. Create this directory,
 
 114 # then configure and build Nominatim in there:
 
 119     cmake $USERHOME/Nominatim
 
 123 # Nominatim is now ready to use. You can continue with
 
 124 # [importing a database from OSM data](../admin/Import.md). If you want to set up
 
 125 # a webserver first, continue reading.
 
 127 # Setting up a webserver
 
 128 # ======================
 
 130 # Option 1: Using Apache
 
 131 # ----------------------
 
 133 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
 
 135 # Apache has a PHP module that can be used to serve Nominatim. To install them
 
 138     sudo apt install -y apache2 libapache2-mod-php
 
 140 # You need to create an alias to the website directory in your apache
 
 141 # configuration. Add a separate nominatim configuration to your webserver:
 
 144 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
 
 145 <Directory "$USERHOME/build/website">
 
 146   Options FollowSymLinks MultiViews
 
 147   AddType text/html   .php
 
 148   DirectoryIndex search.php
 
 152 Alias /nominatim $USERHOME/build/website
 
 157 # Then enable the configuration and restart apache
 
 160     sudo a2enconf nominatim
 
 161     sudo systemctl restart apache2
 
 163 # The Nominatim API is now available at `http://localhost/nominatim/`.
 
 168 # Option 2: Using nginx
 
 169 # ---------------------
 
 171 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
 
 173 # Nginx has no native support for php scripts. You need to set up php-fpm for
 
 174 # this purpose. First install nginx and php-fpm:
 
 176     sudo apt install -y nginx php-fpm
 
 178 # You need to configure php-fpm to listen on a Unix socket.
 
 181 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
 
 183 ; Replace the tcp listener and add the unix socket
 
 184 listen = /var/run/php7.2-fpm.sock
 
 186 ; Ensure that the daemon runs as the correct user
 
 187 listen.owner = www-data
 
 188 listen.group = www-data
 
 191 ; Unix user of FPM processes
 
 195 ; Choose process manager type (static, dynamic, ondemand)
 
 201 # Then create a Nginx configuration to forward http requests to that socket.
 
 204 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
 
 206     listen 80 default_server;
 
 207     listen [::]:80 default_server;
 
 209     root $USERHOME/build/website;
 
 210     index search.php index.html;
 
 212         try_files \$uri \$uri/ @php;
 
 216         fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
 
 217         fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
 
 218         fastcgi_param QUERY_STRING    \$args;
 
 219         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
 
 220         fastcgi_index index.php;
 
 221         include fastcgi_params;
 
 224     location ~ [^/]\.php(/|$) {
 
 225         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 
 226         if (!-f \$document_root\$fastcgi_script_name) {
 
 229         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
 
 230         fastcgi_index search.php;
 
 231         include fastcgi.conf;
 
 238 # Enable the configuration and restart Nginx
 
 241     sudo systemctl restart php7.2-fpm nginx
 
 243 # The Nominatim API is now available at `http://localhost/`.