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 \
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 \
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 # To be able to copy and paste instructions from this manual, export
55 # user name and home directory now like this:
57 if [ "x$USERNAME" == "x" ]; then #DOCS:
58 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
59 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/14/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 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
79 sudo pg_ctlcluster 14 main start #DOCS:
81 sudo systemctl restart postgresql
84 # Finally, we need to add two postgres users: one for the user that does
85 # the import and another for the webserver which should access the database
89 sudo -u postgres createuser -s $USERNAME
90 sudo -u postgres createuser www-data
93 # Installing Nominatim
94 # ====================
96 # Building and Configuration
97 # --------------------------
99 # Get the source code from Github and change into the source directory
101 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
103 git clone --recursive https://github.com/openstreetmap/Nominatim.git
106 cd $USERHOME/Nominatim #DOCS:
109 # When installing the latest source from github, you also need to
110 # download the country grid:
112 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
113 wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
116 # The code must be built in a separate directory. Create this directory,
117 # then configure and build Nominatim in there:
119 mkdir $USERHOME/build
121 cmake $USERHOME/Nominatim
125 # Nominatim is now ready to use. You can continue with
126 # [importing a database from OSM data](../admin/Import.md). If you want to set up
127 # a webserver first, continue reading.
129 # Setting up a webserver
130 # ======================
132 # The webserver should serve the php scripts from the website directory of your
133 # [project directory](../admin/Import.md#creating-the-project-directory).
134 # This directory needs to exist when being configured.
135 # Therefore set up a project directory and create a website directory:
137 mkdir $USERHOME/nominatim-project
138 mkdir $USERHOME/nominatim-project/website
140 # The import process will populate the directory later.
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 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
175 sudo apache2ctl start #DOCS:
177 sudo systemctl restart apache2
180 # The Nominatim API is now available at `http://localhost/nominatim/`.
185 # Option 2: Using nginx
186 # ---------------------
188 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
190 # Nginx has no native support for php scripts. You need to set up php-fpm for
191 # this purpose. First install nginx and php-fpm:
193 sudo apt install -y nginx php-fpm
195 # You need to configure php-fpm to listen on a Unix socket.
198 sudo tee /etc/php/8.1/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
200 ; Replace the tcp listener and add the unix socket
201 listen = /var/run/php-fpm-nominatim.sock
203 ; Ensure that the daemon runs as the correct user
204 listen.owner = www-data
205 listen.group = www-data
208 ; Unix user of FPM processes
212 ; Choose process manager type (static, dynamic, ondemand)
218 # Then create a Nginx configuration to forward http requests to that socket.
221 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
223 listen 80 default_server;
224 listen [::]:80 default_server;
226 root $USERHOME/nominatim-project/website;
227 index search.php index.html;
229 try_files \$uri \$uri/ @php;
233 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
234 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
235 fastcgi_param QUERY_STRING \$args;
236 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
237 fastcgi_index index.php;
238 include fastcgi_params;
241 location ~ [^/]\.php(/|$) {
242 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
243 if (!-f \$document_root\$fastcgi_script_name) {
246 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
247 fastcgi_index search.php;
248 include fastcgi.conf;
254 # If you have some errors, make sure that php-fpm-nominatim.sock is well under
255 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
256 # to /var/run/php/php-fpm-nominatim.sock.
258 # Enable the configuration and restart Nginx
261 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
262 sudo /usr/sbin/php-fpm8.1 --nodaemonize --fpm-config /etc/php/8.1/fpm/php-fpm.conf & #DOCS:
263 sudo /usr/sbin/nginx & #DOCS:
265 sudo systemctl restart php8.1-fpm nginx
268 # The Nominatim API is now available at `http://localhost/`.