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:
19 sudo apt-get update -qq
21 # Now you can install all packages needed for Nominatim:
23 sudo apt-get 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 libicu-dev virtualenv git
31 # System Configuration
32 # ====================
34 # The following steps are meant to configure a fresh Ubuntu installation
35 # for use with Nominatim. You may skip some of the steps if you have your
36 # OS already configured.
38 # Creating Dedicated User Accounts
39 # --------------------------------
41 # Nominatim will run as a global service on your machine. It is therefore
42 # best to install it under its own separate user account. In the following
43 # we assume this user is called nominatim and the installation will be in
44 # /srv/nominatim. To create the user and directory run:
46 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
48 # You may find a more suitable location if you wish.
50 # The following instructions assume you are logged in as this user.
51 # You can also switch to the user with:
53 # sudo -u nominatim bash
55 # To be able to copy and paste instructions from this manual, export
56 # user name and home directory now like this:
58 if [ "x$USERNAME" == "x" ]; then #DOCS:
59 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
60 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
63 # **Never, ever run the installation as a root user.** You have been warned.
65 # Make sure that system servers can read from the home directory:
69 # Setting up PostgreSQL
70 # ---------------------
72 # Tune the postgresql configuration, which is located in
73 # `/etc/postgresql/14/main/postgresql.conf`. See section *Tuning the PostgreSQL database*
74 # in [the installation page](../admin/Installation.md#tuning-the-postgresql-database)
75 # for the parameters to change.
77 # Restart the postgresql service after updating this config file.
79 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
80 sudo pg_ctlcluster 14 main start #DOCS:
82 sudo systemctl restart postgresql
85 # Finally, we need to add two postgres users: one for the user that does
86 # the import and another for the webserver which should access the database
90 sudo -u postgres createuser -s $USERNAME
91 sudo -u postgres createuser www-data
94 # Installing Nominatim
95 # ====================
97 # Building and Configuration
98 # --------------------------
100 # Get the source code from Github and change into the source directory
102 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
104 git clone https://github.com/osm-search/Nominatim.git
107 cd $USERHOME/Nominatim #DOCS:
110 # When installing the latest source from github, you also need to
111 # download the country grid:
113 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
114 wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
117 # Nominatim needs osm2pgsql >= 1.8. The version that comes with Ubuntu is
118 # too old. Download and compile your own:
121 git clone https://github.com/osm2pgsql-dev/osm2pgsql
122 mkdir osm2pgsql-build
127 cd $USERHOME/Nominatim
129 # Nominatim should be installed in a separate Python virtual environment.
130 # Create the virtual environment:
132 virtualenv $USERHOME/nominatim-venv
134 # We want the faster binary version pf psycopg, so install that:
136 $USERHOME/nominatim-venv/bin/pip install psycopg[binary]
138 # Now install Nominatim using pip:
140 cd $USERHOME/Nominatim
141 $USERHOME/nominatim-venv/bin/pip install packaging/nominatim-db
143 # Nominatim is now ready to use. You can continue with
144 # [importing a database from OSM data](../admin/Import.md). If you want to set up
145 # the API frontend first, continue reading.
147 # Setting up the Python frontend
148 # ==============================
150 # The Python frontend is contained in the nominatim-api package. To run
151 # the API as a webservice, you also need falcon with uvicorn to serve the API.
152 # It is generally recommended to run falcon/uvicorn on top of gunicorn.
154 # To install all packages, run:
157 $USERHOME/nominatim-venv/bin/pip install falcon uvicorn gunicorn
158 cd $USERHOME/Nominatim
159 $USERHOME/nominatim-venv/bin/pip install packaging/nominatim-api
163 # Next you need to create a systemd job that runs Nominatim on gunicorn.
164 # First create a systemd job that manages the socket file:
167 sudo tee /etc/systemd/system/nominatim.socket << EOFSOCKETSYSTEMD
169 Description=Gunicorn socket for Nominatim
172 ListenStream=/run/nominatim.sock
176 WantedBy=multi-user.target
180 # Then create the service for Nominatim itself.
183 sudo tee /etc/systemd/system/nominatim.service << EOFNOMINATIMSYSTEMD
185 Description=Nominatim running as a gunicorn application
187 Requires=nominatim.socket
193 WorkingDirectory=$USERHOME/nominatim-project
194 ExecStart=$USERHOME/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker "nominatim_api.server.falcon.server:run_wsgi()"
195 ExecReload=/bin/kill -s HUP \$MAINPID
201 WantedBy=multi-user.target
205 # Activate the services:
207 if [ "x$NOSYSTEMD" != "xyes" ]; then #DOCS:
208 sudo systemctl daemon-reload
209 sudo systemctl enable nominatim.socket
210 sudo systemctl start nominatim.socket
211 sudo systemctl enable nominatim.service
214 # Setting up a webserver
215 # ======================
217 # The webserver is only needed as a proxy between the public interface
218 # and the gunicorn service.
220 # The frontend will need configuration information from the project
221 # directory, which will be populated later
222 # [during the import process](../admin/Import.md#creating-the-project-directory)
223 # Already create the project directory itself now:
225 mkdir $USERHOME/nominatim-project
228 # Option 1: Using Apache
229 # ----------------------
231 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
233 # First install apache itself and enable the proxy module:
235 sudo apt-get install -y apache2
236 sudo a2enmod proxy_http
239 # To set up proxying for Apache add the following configuration:
242 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
244 ProxyPass /nominatim "unix:/run/nominatim.sock|http://localhost/"
249 # Then enable the configuration and restart apache
253 sudo a2enconf nominatim
256 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
257 sudo apache2ctl start #DOCS:
259 sudo systemctl restart apache2
262 # The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
263 # to the status output `http://localhost/nominatim/status` to test if everything is ok.
268 # Option 2: Using nginx
269 # ---------------------
271 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
273 # First install nginx itself:
275 sudo apt-get install -y nginx
278 # Then create a Nginx configuration to forward http requests to that socket.
281 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
283 listen 80 default_server;
284 listen [::]:80 default_server;
286 root $USERHOME/nominatim-project/website;
289 location /nominatim/ {
290 proxy_set_header Host \$http_host;
291 proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
292 proxy_set_header X-Forwarded-Proto \$scheme;
294 proxy_pass http://unix:/run/nominatim.sock:/;
300 # Enable the configuration and restart Nginx
303 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
304 sudo /usr/sbin/nginx & #DOCS:
306 sudo systemctl restart nginx
309 # The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
310 # to the status output `http://localhost/nominatim/status` to test if everything is ok.