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-24.sh.
11 # Installing the Required Software
12 # ================================
14 # These instructions expect that you have a freshly installed Ubuntu 24.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 osm2pgsql postgresql-postgis postgresql-postgis-scripts \
24 pkg-config libicu-dev virtualenv git
28 # System Configuration
29 # ====================
31 # The following steps are meant to configure a fresh Ubuntu installation
32 # for use with Nominatim. You may skip some of the steps if you have your
33 # OS already configured.
35 # Creating Dedicated User Accounts
36 # --------------------------------
38 # Nominatim will run as a global service on your machine. It is therefore
39 # best to install it under its own separate user account. In the following
40 # we assume this user is called nominatim and the installation will be in
41 # /srv/nominatim. To create the user and directory run:
43 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
45 # You may find a more suitable location if you wish.
47 # The following instructions assume you are logged in as this user.
48 # You can also switch to the user with:
50 # sudo -u nominatim bash
52 # To be able to copy and paste instructions from this manual, export
53 # user name and home directory now like this:
55 if [ "x$USERNAME" == "x" ]; then #DOCS:
56 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
57 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
60 # **Never, ever run the installation as a root user.** You have been warned.
62 # Make sure that system servers can read from the home directory:
66 # Setting up PostgreSQL
67 # ---------------------
69 # Tune the postgresql configuration, which is located in
70 # `/etc/postgresql/16/main/postgresql.conf`. See section *Tuning the PostgreSQL database*
71 # in [the installation page](../admin/Installation.md#tuning-the-postgresql-database)
72 # for the parameters to change.
74 # Restart the postgresql service after updating this config file.
76 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
77 sudo pg_ctlcluster 16 main start #DOCS:
79 sudo systemctl restart postgresql
82 # Finally, we need to add two postgres users: one for the user that does
83 # the import and another for the webserver which should access the database
87 sudo -u postgres createuser -s $USERNAME
88 sudo -u postgres createuser www-data
91 # Installing Nominatim
92 # ====================
94 # Building and Configuration
95 # --------------------------
97 # Get the source code from Github and change into the source directory
99 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
101 git clone https://github.com/openstreetmap/Nominatim.git
104 cd $USERHOME/Nominatim #DOCS:
107 # When installing the latest source from github, you also need to
108 # download the country grid:
110 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
111 wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
114 # Nominatim should be installed in a separate Python virtual environment.
115 # Create the virtual environment:
117 virtualenv $USERHOME/nominatim-venv
119 # Now install Nominatim using pip:
121 cd $USERHOME/Nominatim
122 $USERHOME/nominatim-venv/bin/pip install packaging/nominatim-db
124 # Nominatim is now ready to use. The nominatim binary is available at
125 # `$USERHOME/venv/bin/nominatim`. If you want to have 'nominatim' in your
126 # path, simply activate the virtual environment:
129 # . $USERHOME/nominatim-venv/bin/activate
132 # You can continue with
133 # [importing a database from OSM data](../admin/Import.md). If you want to set up
134 # the API frontend first, continue reading.
136 # Setting up the Python frontend
137 # ==============================
139 # The Python frontend is contained in the nominatim-api package. To run
140 # the API as a webservice, you also need falcon with uvicorn to serve the API.
141 # It is generally recommended to run falcon/uvicorn on top of gunicorn.
143 # To install all packages, run:
146 $USERHOME/nominatim-venv/bin/pip install psycopg[binary] falcon uvicorn gunicorn
147 cd $USERHOME/Nominatim
148 $USERHOME/nominatim-venv/bin/pip install packaging/nominatim-api
151 # Next you need to create a systemd job that runs Nominatim on gunicorn.
152 # First create a systemd job that manages the socket file:
155 sudo tee /etc/systemd/system/nominatim.socket << EOFSOCKETSYSTEMD
157 Description=Gunicorn socket for Nominatim
160 ListenStream=/run/nominatim.sock
164 WantedBy=multi-user.target
168 # Then create the service for Nominatim itself.
171 sudo tee /etc/systemd/system/nominatim.service << EOFNOMINATIMSYSTEMD
173 Description=Nominatim running as a gunicorn application
175 Requires=nominatim.socket
179 Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
182 WorkingDirectory=$USERHOME/nominatim-project
183 ExecStart=$USERHOME/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker nominatim_api.server.falcon.server:run_wsgi
184 ExecReload=/bin/kill -s HUP \$MAINPID
185 StandardOutput=append:/var/log/gunicorn-nominatim.log
186 StandardError=inherit
192 WantedBy=multi-user.target
196 # Activate the services:
198 if [ "x$NOSYSTEMD" != "xyes" ]; then #DOCS:
199 sudo systemctl daemon-reload
200 sudo systemctl enable nominatim.socket
201 sudo systemctl start nominatim.socket
202 sudo systemctl enable nominatim.service
205 # Setting up a webserver
206 # ======================
208 # The webserver is only needed as a proxy between the public interface
209 # and the gunicorn service.
211 # The frontend will need configuration information from the project
212 # directory, which will be populated later
213 # [during the import process](../admin/Import.md#creating-the-project-directory)
214 # Already create the project directory itself now:
216 mkdir $USERHOME/nominatim-project
219 # Option 1: Using Apache
220 # ----------------------
222 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
224 # First install apache itself and enable the proxy module:
226 sudo apt-get install -y apache2
227 sudo a2enmod proxy_http
230 # To set up proxying for Apache add the following configuration:
233 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
235 ProxyPass /nominatim "unix:/run/nominatim.sock|http://localhost/"
240 # Then enable the configuration and restart apache
244 sudo a2enconf nominatim
247 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
248 sudo apache2ctl start #DOCS:
250 sudo systemctl restart apache2
253 # The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
254 # to the status output `http://localhost/nominatim/status` to test if everything is ok.
259 # Option 2: Using nginx
260 # ---------------------
262 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
264 # First install nginx itself:
266 sudo apt-get install -y nginx
269 # Then create a Nginx configuration to forward http requests to that socket.
272 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
274 listen 80 default_server;
275 listen [::]:80 default_server;
277 root $USERHOME/nominatim-project/website;
280 location /nominatim/ {
281 proxy_set_header Host \$http_host;
282 proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
283 proxy_set_header X-Forwarded-Proto \$scheme;
285 proxy_pass http://unix:/run/nominatim.sock:/;
291 # Enable the configuration and restart Nginx
294 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
295 sudo /usr/sbin/nginx & #DOCS:
297 sudo systemctl restart nginx
300 # The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
301 # to the status output `http://localhost/nominatim/status` to test if everything is ok.