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 python3-pip \
31 python3-icu python3-datrie python3-yaml git
33 # Some of the Python packages that come with Ubuntu 20.04 are too old, so
34 # install the latest version from pip:
36 pip3 install --user sqlalchemy GeoAlchemy2 asyncpg
40 # System Configuration
41 # ====================
43 # The following steps are meant to configure a fresh Ubuntu installation
44 # for use with Nominatim. You may skip some of the steps if you have your
45 # OS already configured.
47 # Creating Dedicated User Accounts
48 # --------------------------------
50 # Nominatim will run as a global service on your machine. It is therefore
51 # best to install it under its own separate user account. In the following
52 # we assume this user is called nominatim and the installation will be in
53 # /srv/nominatim. To create the user and directory run:
55 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
57 # You may find a more suitable location if you wish.
59 # The following instructions assume you are logged in as this user.
60 # You can also switch to the user with:
62 # sudo -u nominatim bash
64 # To be able to copy and paste instructions from this manual, export
65 # user name and home directory now like this:
67 if [ "x$USERNAME" == "x" ]; then #DOCS:
68 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
69 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
72 # **Never, ever run the installation as a root user.** You have been warned.
74 # Make sure that system servers can read from the home directory:
78 # Setting up PostgreSQL
79 # ---------------------
81 # Tune the postgresql configuration, which is located in
82 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
83 # [the installation page](../admin/Installation.md#postgresql-tuning)
84 # for the parameters to change.
86 # Restart the postgresql service after updating this config file.
88 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
89 sudo pg_ctlcluster 12 main start #DOCS:
91 sudo systemctl restart postgresql
94 # Finally, we need to add two postgres users: one for the user that does
95 # the import and another for the webserver which should access the database
99 sudo -u postgres createuser -s $USERNAME
100 sudo -u postgres createuser www-data
103 # Installing Nominatim
104 # ====================
106 # Building and Configuration
107 # --------------------------
109 # Get the source code from Github and change into the source directory
111 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
113 git clone --recursive https://github.com/openstreetmap/Nominatim.git
116 cd $USERHOME/Nominatim #DOCS:
119 # When installing the latest source from github, you also need to
120 # download the country grid:
122 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
123 wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
126 # The code must be built in a separate directory. Create this directory,
127 # then configure and build Nominatim in there:
129 mkdir $USERHOME/build
131 cmake $USERHOME/Nominatim
135 # Nominatim is now ready to use. You can continue with
136 # [importing a database from OSM data](../admin/Import.md). If you want to set up
137 # a webserver first, continue reading.
139 # Setting up a webserver
140 # ======================
142 # The webserver should serve the php scripts from the website directory of your
143 # [project directory](../admin/Import.md#creating-the-project-directory).
144 # This directory needs to exist when being configured.
145 # Therefore set up a project directory and create a website directory:
147 mkdir $USERHOME/nominatim-project
148 mkdir $USERHOME/nominatim-project/website
150 # The import process will populate the directory later.
153 # Option 1: Using Apache
154 # ----------------------
156 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
158 # Apache has a PHP module that can be used to serve Nominatim. To install them
161 sudo apt install -y apache2 libapache2-mod-php
163 # You need to create an alias to the website directory in your apache
164 # configuration. Add a separate nominatim configuration to your webserver:
167 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
168 <Directory "$USERHOME/nominatim-project/website">
169 Options FollowSymLinks MultiViews
170 AddType text/html .php
171 DirectoryIndex search.php
175 Alias /nominatim $USERHOME/nominatim-project/website
180 # Then enable the configuration and restart apache
183 sudo a2enconf nominatim
184 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
185 sudo apache2ctl start #DOCS:
187 sudo systemctl restart apache2
190 # The Nominatim API is now available at `http://localhost/nominatim/`.
195 # Option 2: Using nginx
196 # ---------------------
198 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
200 # Nginx has no native support for php scripts. You need to set up php-fpm for
201 # this purpose. First install nginx and php-fpm:
203 sudo apt install -y nginx php-fpm
205 # You need to configure php-fpm to listen on a Unix socket.
208 sudo tee /etc/php/7.4/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
210 ; Replace the tcp listener and add the unix socket
211 listen = /var/run/php-fpm-nominatim.sock
213 ; Ensure that the daemon runs as the correct user
214 listen.owner = www-data
215 listen.group = www-data
218 ; Unix user of FPM processes
222 ; Choose process manager type (static, dynamic, ondemand)
228 # Then create a Nginx configuration to forward http requests to that socket.
231 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
233 listen 80 default_server;
234 listen [::]:80 default_server;
236 root $USERHOME/nominatim-project/website;
237 index search.php index.html;
239 try_files \$uri \$uri/ @php;
243 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
244 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
245 fastcgi_param QUERY_STRING \$args;
246 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
247 fastcgi_index index.php;
248 include fastcgi_params;
251 location ~ [^/]\.php(/|$) {
252 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
253 if (!-f \$document_root\$fastcgi_script_name) {
256 fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
257 fastcgi_index search.php;
258 include fastcgi.conf;
264 # If you have some errors, make sure that php-fpm-nominatim.sock is well under
265 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
266 # to /var/run/php/php-fpm-nominatim.sock.
268 # Enable the configuration and restart Nginx
271 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
272 sudo /usr/sbin/php-fpm7.4 --nodaemonize --fpm-config /etc/php/7.4/fpm/php-fpm.conf & #DOCS:
273 sudo /usr/sbin/nginx & #DOCS:
275 sudo systemctl restart php7.4-fpm nginx
278 # The Nominatim API is now available at `http://localhost/`.