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-22.sh.
11 # Installing the Required Software
12 # ================================
14 # These instructions expect that you have a freshly installed Ubuntu 22.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 build-essential cmake g++ libboost-dev libboost-system-dev \
24 libboost-filesystem-dev libexpat1-dev zlib1g-dev \
25 libbz2-dev libpq-dev liblua5.3-dev lua5.3 lua-dkjson \
26 nlohmann-json3-dev postgresql-14-postgis-3 \
27 postgresql-contrib-14 postgresql-14-postgis-3-scripts \
28 php-cli php-pgsql php-intl libicu-dev python3-dotenv \
29 python3-psycopg2 python3-psutil python3-jinja2 \
30 python3-icu python3-datrie python3-sqlalchemy \
31 python3-asyncpg 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 # The following instructions assume you are logged in as this user.
54 # You can also switch to the user with:
56 # sudo -u nominatim bash
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/14/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 14 main start #DOCS:
85 sudo systemctl restart postgresql
88 # Finally, we need to add two postgres users: one for the user that does
89 # the import and another for the webserver which should access the database
93 sudo -u postgres createuser -s $USERNAME
94 sudo -u postgres createuser www-data
97 # Installing Nominatim
98 # ====================
100 # Building and Configuration
101 # --------------------------
103 # Get the source code from Github and change into the source directory
105 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
107 git clone --recursive https://github.com/openstreetmap/Nominatim.git
110 cd $USERHOME/Nominatim #DOCS:
113 # When installing the latest source from github, you also need to
114 # download the country grid:
116 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
117 wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
120 # The code must be built in a separate directory. Create this directory,
121 # then configure and build Nominatim in there:
123 mkdir $USERHOME/build
125 cmake $USERHOME/Nominatim
129 # Nominatim is now ready to use. You can continue with
130 # [importing a database from OSM data](../admin/Import.md). If you want to set up
131 # a webserver first, continue reading.
133 # Setting up a webserver
134 # ======================
136 # The webserver should serve the php scripts from the website directory of your
137 # [project directory](../admin/Import.md#creating-the-project-directory).
138 # This directory needs to exist when being configured.
139 # Therefore set up a project directory and create a website directory:
141 mkdir $USERHOME/nominatim-project
142 mkdir $USERHOME/nominatim-project/website
144 # The import process will populate the directory later.
147 # Option 1: Using Apache
148 # ----------------------
150 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
152 # Apache has a PHP module that can be used to serve Nominatim. To install them
155 sudo apt install -y apache2 libapache2-mod-php
157 # You need to create an alias to the website directory in your apache
158 # configuration. Add a separate nominatim configuration to your webserver:
161 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
162 <Directory "$USERHOME/nominatim-project/website">
163 Options FollowSymLinks MultiViews
164 AddType text/html .php
165 DirectoryIndex search.php
169 Alias /nominatim $USERHOME/nominatim-project/website
174 # Then enable the configuration and restart apache
177 sudo a2enconf nominatim
178 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
179 sudo apache2ctl start #DOCS:
181 sudo systemctl restart apache2
184 # The Nominatim API is now available at `http://localhost/nominatim/`.
189 # Option 2: Using nginx
190 # ---------------------
192 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
194 # Nginx has no native support for php scripts. You need to set up php-fpm for
195 # this purpose. First install nginx and php-fpm:
197 sudo apt install -y nginx php-fpm
199 # You need to configure php-fpm to listen on a Unix socket.
202 sudo tee /etc/php/8.1/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
204 ; Replace the tcp listener and add the unix socket
205 listen = /var/run/php-fpm-nominatim.sock
207 ; Ensure that the daemon runs as the correct user
208 listen.owner = www-data
209 listen.group = www-data
212 ; Unix user of FPM processes
216 ; Choose process manager type (static, dynamic, ondemand)
222 # Then create a Nginx configuration to forward http requests to that socket.
225 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
227 listen 80 default_server;
228 listen [::]:80 default_server;
230 root $USERHOME/nominatim-project/website;
231 index search.php index.html;
233 try_files \$uri \$uri/ @php;
237 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
238 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
239 fastcgi_param QUERY_STRING \$args;
240 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
241 fastcgi_index index.php;
242 include fastcgi_params;
245 location ~ [^/]\.php(/|$) {
246 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
247 if (!-f \$document_root\$fastcgi_script_name) {
250 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
251 fastcgi_index search.php;
252 include fastcgi.conf;
258 # If you have some errors, make sure that php-fpm-nominatim.sock is well under
259 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
260 # to /var/run/php/php-fpm-nominatim.sock.
262 # Enable the configuration and restart Nginx
265 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
266 sudo /usr/sbin/php-fpm8.1 --nodaemonize --fpm-config /etc/php/8.1/fpm/php-fpm.conf & #DOCS:
267 sudo /usr/sbin/nginx & #DOCS:
269 sudo systemctl restart php8.1-fpm nginx
272 # The Nominatim API is now available at `http://localhost/`.