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 libicu-dev python3-pip \
33 python3-psycopg2 python3-psutil python3-jinja2 python3-icu git \
34 python3-argparse-manpage
36 # The python-dotenv package that comes with Ubuntu 18.04 is too old, so
37 # install the latest version from pip:
39 pip3 install python-dotenv
42 # System Configuration
43 # ====================
45 # The following steps are meant to configure a fresh Ubuntu installation
46 # for use with Nominatim. You may skip some of the steps if you have your
47 # OS already configured.
49 # Creating Dedicated User Accounts
50 # --------------------------------
52 # Nominatim will run as a global service on your machine. It is therefore
53 # best to install it under its own separate user account. In the following
54 # we assume this user is called nominatim and the installation will be in
55 # /srv/nominatim. To create the user and directory run:
57 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
59 # You may find a more suitable location if you wish.
61 # To be able to copy and paste instructions from this manual, export
62 # user name and home directory now like this:
64 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
65 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
67 # **Never, ever run the installation as a root user.** You have been warned.
69 # Make sure that system servers can read from the home directory:
73 # Setting up PostgreSQL
74 # ---------------------
76 # Tune the postgresql configuration, which is located in
77 # `/etc/postgresql/10/main/postgresql.conf`. See section *Postgres Tuning* in
78 # [the installation page](../admin/Installation.md#postgresql-tuning)
79 # for the parameters to change.
81 # Restart the postgresql service after updating this config file.
83 sudo systemctl restart postgresql
86 # Finally, we need to add two postgres users: one for the user that does
87 # the import and another for the webserver which should access the database
91 sudo -u postgres createuser -s $USERNAME
92 sudo -u postgres createuser www-data
95 # Installing Nominatim
96 # ====================
98 # Building and Configuration
99 # --------------------------
101 # Get the source code from Github and change into the source directory
103 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
105 git clone --recursive git://github.com/openstreetmap/Nominatim.git
108 cd $USERHOME/Nominatim #DOCS:
111 # When installing the latest source from github, you also need to
112 # download the country grid:
114 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
115 wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
118 # The code must be built in a separate directory. Create this directory,
119 # then configure and build Nominatim in there:
121 mkdir $USERHOME/build
123 cmake $USERHOME/Nominatim
128 # Nominatim is now ready to use. You can continue with
129 # [importing a database from OSM data](../admin/Import.md). If you want to set up
130 # a webserver first, continue reading.
132 # Setting up a webserver
133 # ======================
135 # The webserver should serve the php scripts from the website directory of your
136 # [project directory](../admin/import.md#creating-the-project-directory).
137 # Therefore set up a project directory and populate the website directory:
139 mkdir $USERHOME/nominatim-project
140 cd $USERHOME/nominatim-project
141 nominatim refresh --website
143 # Option 1: Using Apache
144 # ----------------------
146 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
148 # Apache has a PHP module that can be used to serve Nominatim. To install them
151 sudo apt install -y apache2 libapache2-mod-php
153 # You need to create an alias to the website directory in your apache
154 # configuration. Add a separate nominatim configuration to your webserver:
157 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
158 <Directory "$USERHOME/nominatim-project/website">
159 Options FollowSymLinks MultiViews
160 AddType text/html .php
161 DirectoryIndex search.php
165 Alias /nominatim $USERHOME/nominatim-project/website
170 # Then enable the configuration and restart apache
173 sudo a2enconf nominatim
174 sudo systemctl restart apache2
176 # The Nominatim API is now available at `http://localhost/nominatim/`.
181 # Option 2: Using nginx
182 # ---------------------
184 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
186 # Nginx has no native support for php scripts. You need to set up php-fpm for
187 # this purpose. First install nginx and php-fpm:
189 sudo apt install -y nginx php-fpm
191 # You need to configure php-fpm to listen on a Unix socket.
194 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
196 ; Replace the tcp listener and add the unix socket
197 listen = /var/run/php7.2-fpm.sock
199 ; Ensure that the daemon runs as the correct user
200 listen.owner = www-data
201 listen.group = www-data
204 ; Unix user of FPM processes
208 ; Choose process manager type (static, dynamic, ondemand)
214 # Then create a Nginx configuration to forward http requests to that socket.
217 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
219 listen 80 default_server;
220 listen [::]:80 default_server;
222 root $USERHOME/nominatim-project/website;
223 index search.php index.html;
225 try_files \$uri \$uri/ @php;
229 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
230 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
231 fastcgi_param QUERY_STRING \$args;
232 fastcgi_pass unix:/var/run/php7.2-fpm.sock;
233 fastcgi_index index.php;
234 include fastcgi_params;
237 location ~ [^/]\.php(/|$) {
238 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
239 if (!-f \$document_root\$fastcgi_script_name) {
242 fastcgi_pass unix:/var/run/php7.2-fpm.sock;
243 fastcgi_index search.php;
244 include fastcgi.conf;
251 # Enable the configuration and restart Nginx
254 sudo systemctl restart php7.2-fpm nginx
256 # The Nominatim API is now available at `http://localhost/`.