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:
8 # *Note:* these installation instructions are also available in executable
9 # form for use with vagrant under vagrant/Install-on-Ubuntu-20.sh.
11 # Installing the Required Software
12 # ================================
14 # These instructions expect that you have a freshly installed Ubuntu 20.04.
16 # Make sure all packages are up-to-date by running:
21 # Now you can install all packages needed for Nominatim:
23 sudo apt install -y php-cgi
24 sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
25 libboost-filesystem-dev libexpat1-dev zlib1g-dev \
26 libbz2-dev libpq-dev liblua5.3-dev lua5.3 \
27 postgresql-12-postgis-3 \
28 postgresql-contrib-12 postgresql-12-postgis-3-scripts \
29 php-cli php-pgsql php-intl libicu-dev python3-dotenv \
30 python3-psycopg2 python3-psutil python3-jinja2 \
31 python3-icu python3-datrie python3-yaml git
34 # System Configuration
35 # ====================
37 # The following steps are meant to configure a fresh Ubuntu installation
38 # for use with Nominatim. You may skip some of the steps if you have your
39 # OS already configured.
41 # Creating Dedicated User Accounts
42 # --------------------------------
44 # Nominatim will run as a global service on your machine. It is therefore
45 # best to install it under its own separate user account. In the following
46 # we assume this user is called nominatim and the installation will be in
47 # /srv/nominatim. To create the user and directory run:
49 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
51 # You may find a more suitable location if you wish.
53 # To be able to copy and paste instructions from this manual, export
54 # user name and home directory now like this:
56 if [ "x$USERNAME" == "x" ]; then #DOCS:
57 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
58 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
61 # **Never, ever run the installation as a root user.** You have been warned.
63 # Make sure that system servers can read from the home directory:
67 # Setting up PostgreSQL
68 # ---------------------
70 # Tune the postgresql configuration, which is located in
71 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
72 # [the installation page](../admin/Installation.md#postgresql-tuning)
73 # for the parameters to change.
75 # Restart the postgresql service after updating this config file.
77 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
78 sudo pg_ctlcluster 12 main start #DOCS:
80 sudo systemctl restart postgresql
83 # Finally, we need to add two postgres users: one for the user that does
84 # the import and another for the webserver which should access the database
88 sudo -u postgres createuser -s $USERNAME
89 sudo -u postgres createuser www-data
92 # Installing Nominatim
93 # ====================
95 # Building and Configuration
96 # --------------------------
98 # Get the source code from Github and change into the source directory
100 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
102 git clone --recursive https://github.com/openstreetmap/Nominatim.git
105 cd $USERHOME/Nominatim #DOCS:
108 # When installing the latest source from github, you also need to
109 # download the country grid:
111 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
112 wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
115 # The code must be built in a separate directory. Create this directory,
116 # then configure and build Nominatim in there:
118 mkdir $USERHOME/build
120 cmake $USERHOME/Nominatim
124 # Nominatim is now ready to use. You can continue with
125 # [importing a database from OSM data](../admin/Import.md). If you want to set up
126 # a webserver first, continue reading.
128 # Setting up a webserver
129 # ======================
131 # The webserver should serve the php scripts from the website directory of your
132 # [project directory](../admin/Import.md#creating-the-project-directory).
133 # This directory needs to exist when being configured.
134 # Therefore set up a project directory and create a website directory:
136 mkdir $USERHOME/nominatim-project
137 mkdir $USERHOME/nominatim-project/website
139 # The import process will populate the directory later.
142 # Option 1: Using Apache
143 # ----------------------
145 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
147 # Apache has a PHP module that can be used to serve Nominatim. To install them
150 sudo apt install -y apache2 libapache2-mod-php
152 # You need to create an alias to the website directory in your apache
153 # configuration. Add a separate nominatim configuration to your webserver:
156 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
157 <Directory "$USERHOME/nominatim-project/website">
158 Options FollowSymLinks MultiViews
159 AddType text/html .php
160 DirectoryIndex search.php
164 Alias /nominatim $USERHOME/nominatim-project/website
169 # Then enable the configuration and restart apache
172 sudo a2enconf nominatim
173 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
174 sudo apache2ctl start #DOCS:
176 sudo systemctl restart apache2
179 # The Nominatim API is now available at `http://localhost/nominatim/`.
184 # Option 2: Using nginx
185 # ---------------------
187 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
189 # Nginx has no native support for php scripts. You need to set up php-fpm for
190 # this purpose. First install nginx and php-fpm:
192 sudo apt install -y nginx php-fpm
194 # You need to configure php-fpm to listen on a Unix socket.
197 sudo tee /etc/php/7.4/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
199 ; Replace the tcp listener and add the unix socket
200 listen = /var/run/php-fpm-nominatim.sock
202 ; Ensure that the daemon runs as the correct user
203 listen.owner = www-data
204 listen.group = www-data
207 ; Unix user of FPM processes
211 ; Choose process manager type (static, dynamic, ondemand)
217 # Then create a Nginx configuration to forward http requests to that socket.
220 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
222 listen 80 default_server;
223 listen [::]:80 default_server;
225 root $USERHOME/nominatim-project/website;
226 index search.php index.html;
228 try_files \$uri \$uri/ @php;
232 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
233 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
234 fastcgi_param QUERY_STRING \$args;
235 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
236 fastcgi_index index.php;
237 include fastcgi_params;
240 location ~ [^/]\.php(/|$) {
241 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
242 if (!-f \$document_root\$fastcgi_script_name) {
245 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
246 fastcgi_index search.php;
247 include fastcgi.conf;
253 # If you have some errors, make sure that php-fpm-nominatim.sock is well under
254 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
255 # to /var/run/php/php-fpm-nominatim.sock.
257 # Enable the configuration and restart Nginx
260 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
261 sudo /usr/sbin/php-fpm7.4 --nodaemonize --fpm-config /etc/php/7.4/fpm/php-fpm.conf & #DOCS:
262 sudo /usr/sbin/nginx & #DOCS:
264 sudo systemctl restart php7.4-fpm nginx
267 # The Nominatim API is now available at `http://localhost/`.