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 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 lua-dkjson \
27 postgresql-server-dev-14 postgresql-14-postgis-3 \
28 postgresql-contrib-14 postgresql-14-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-sqlalchemy \
32 python3-geoalchemy2 python3-asyncpg git
35 # System Configuration
36 # ====================
38 # The following steps are meant to configure a fresh Ubuntu installation
39 # for use with Nominatim. You may skip some of the steps if you have your
40 # OS already configured.
42 # Creating Dedicated User Accounts
43 # --------------------------------
45 # Nominatim will run as a global service on your machine. It is therefore
46 # best to install it under its own separate user account. In the following
47 # we assume this user is called nominatim and the installation will be in
48 # /srv/nominatim. To create the user and directory run:
50 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
52 # You may find a more suitable location if you wish.
54 # The following instructions assume you are logged in as this user.
55 # You can also switch to the user with:
57 # sudo -u nominatim bash
59 # To be able to copy and paste instructions from this manual, export
60 # user name and home directory now like this:
62 if [ "x$USERNAME" == "x" ]; then #DOCS:
63 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
64 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/14/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 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
84 sudo pg_ctlcluster 14 main start #DOCS:
86 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 https://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://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
130 # Nominatim is now ready to use. You can continue with
131 # [importing a database from OSM data](../admin/Import.md). If you want to set up
132 # a webserver first, continue reading.
134 # Setting up a webserver
135 # ======================
137 # The webserver should serve the php scripts from the website directory of your
138 # [project directory](../admin/Import.md#creating-the-project-directory).
139 # This directory needs to exist when being configured.
140 # Therefore set up a project directory and create a website directory:
142 mkdir $USERHOME/nominatim-project
143 mkdir $USERHOME/nominatim-project/website
145 # 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 and restart apache
178 sudo a2enconf nominatim
179 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
180 sudo apache2ctl start #DOCS:
182 sudo systemctl restart apache2
185 # The Nominatim API is now available at `http://localhost/nominatim/`.
190 # Option 2: Using nginx
191 # ---------------------
193 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
195 # Nginx has no native support for php scripts. You need to set up php-fpm for
196 # this purpose. First install nginx and php-fpm:
198 sudo apt install -y nginx php-fpm
200 # You need to configure php-fpm to listen on a Unix socket.
203 sudo tee /etc/php/8.1/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
205 ; Replace the tcp listener and add the unix socket
206 listen = /var/run/php-fpm-nominatim.sock
208 ; Ensure that the daemon runs as the correct user
209 listen.owner = www-data
210 listen.group = www-data
213 ; Unix user of FPM processes
217 ; Choose process manager type (static, dynamic, ondemand)
223 # Then create a Nginx configuration to forward http requests to that socket.
226 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
228 listen 80 default_server;
229 listen [::]:80 default_server;
231 root $USERHOME/nominatim-project/website;
232 index search.php index.html;
234 try_files \$uri \$uri/ @php;
238 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
239 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
240 fastcgi_param QUERY_STRING \$args;
241 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
242 fastcgi_index index.php;
243 include fastcgi_params;
246 location ~ [^/]\.php(/|$) {
247 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
248 if (!-f \$document_root\$fastcgi_script_name) {
251 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
252 fastcgi_index search.php;
253 include fastcgi.conf;
259 # If you have some errors, make sure that php-fpm-nominatim.sock is well under
260 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
261 # to /var/run/php/php-fpm-nominatim.sock.
263 # Enable the configuration and restart Nginx
266 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
267 sudo /usr/sbin/php-fpm8.1 --nodaemonize --fpm-config /etc/php/8.1/fpm/php-fpm.conf & #DOCS:
268 sudo /usr/sbin/nginx & #DOCS:
270 sudo systemctl restart php8.1-fpm nginx
273 # The Nominatim API is now available at `http://localhost/`.