3 # hacks for broken vagrant box #DOCS:
4 sudo rm -f /var/lib/dpkg/lock #DOCS:
5 sudo update-locale LANG=en_US.UTF-8 #DOCS:
6 export APT_LISTCHANGES_FRONTEND=none #DOCS:
7 export DEBIAN_FRONTEND=noninteractive #DOCS:
9 # *Note:* these installation instructions are also available in executable
10 # form for use with vagrant under vagrant/Install-on-Ubuntu-20.sh.
12 # Installing the Required Software
13 # ================================
15 # These instructions expect that you have a freshly installed Ubuntu 20.04.
17 # Make sure all packages are are up-to-date by running:
22 -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" \ #DOCS:
23 --allow-downgrades --allow-remove-essential --allow-change-held-packages \ #DOCS:
24 -fuy install grub-pc #DOCS:
27 # Now you can install all packages needed for Nominatim:
29 sudo apt install -y php-cgi
30 sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
31 libboost-filesystem-dev libexpat1-dev zlib1g-dev \
32 libbz2-dev libpq-dev libproj-dev \
33 postgresql-server-dev-12 postgresql-12-postgis-3 \
34 postgresql-contrib-12 postgresql-12-postgis-3-scripts \
35 php php-pgsql php-intl python3-dotenv \
36 python3-psycopg2 python3-psutil git
39 # System Configuration
40 # ====================
42 # The following steps are meant to configure a fresh Ubuntu installation
43 # for use with Nominatim. You may skip some of the steps if you have your
44 # OS already configured.
46 # Creating Dedicated User Accounts
47 # --------------------------------
49 # Nominatim will run as a global service on your machine. It is therefore
50 # best to install it under its own separate user account. In the following
51 # we assume this user is called nominatim and the installation will be in
52 # /srv/nominatim. To create the user and directory run:
54 # sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
56 # You may find a more suitable location if you wish.
58 # To be able to copy and paste instructions from this manual, export
59 # user name and home directory now like this:
61 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
62 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
64 # **Never, ever run the installation as a root user.** You have been warned.
66 # Make sure that system servers can read from the home directory:
70 # Setting up PostgreSQL
71 # ---------------------
73 # Tune the postgresql configuration, which is located in
74 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
75 # [the installation page](../admin/Installation.md#postgresql-tuning)
76 # for the parameters to change.
78 # Restart the postgresql service after updating this config file.
80 sudo systemctl restart postgresql
83 # Finally, we need to add two postgres users: one for the user that does
84 # the import and another for the webserver which should access the database
88 sudo -u postgres createuser -s $USERNAME
89 sudo -u postgres createuser www-data
92 # Installing Nominatim
93 # ====================
95 # Building and Configuration
96 # --------------------------
98 # Get the source code from Github and change into the source directory
100 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
102 git clone --recursive git://github.com/openstreetmap/Nominatim.git
105 cd $USERHOME/Nominatim #DOCS:
108 # When installing the latest source from github, you also need to
109 # download the country grid:
111 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
112 wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
115 # The code must be built in a separate directory. Create this directory,
116 # then configure and build Nominatim in there:
118 mkdir $USERHOME/build
120 cmake $USERHOME/Nominatim
124 # Nominatim is now ready to use. You can continue with
125 # [importing a database from OSM data](../admin/Import.md). If you want to set up
126 # a webserver first, continue reading.
128 # Setting up a webserver
129 # ======================
131 # The webserver should serve the php scripts from the website directory of your
132 # [project directory](../admin/import.md#creating-the-project-directory).
133 # Therefore set up a project directory and populate the website directory:
135 mkdir $USERHOME/nominatim-project
136 cd $USERHOME/nominatim-project
137 nominatim refresh --website
140 # Option 1: Using Apache
141 # ----------------------
143 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
145 # Apache has a PHP module that can be used to serve Nominatim. To install them
148 sudo apt install -y apache2 libapache2-mod-php
150 # You need to create an alias to the website directory in your apache
151 # configuration. Add a separate nominatim configuration to your webserver:
154 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
155 <Directory "$USERHOME/nominatim-project/website">
156 Options FollowSymLinks MultiViews
157 AddType text/html .php
158 DirectoryIndex search.php
162 Alias /nominatim $USERHOME/nominatim-project/website
167 # Then enable the configuration and restart apache
170 sudo a2enconf nominatim
171 sudo systemctl restart apache2
173 # The Nominatim API is now available at `http://localhost/nominatim/`.
178 # Option 2: Using nginx
179 # ---------------------
181 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
183 # Nginx has no native support for php scripts. You need to set up php-fpm for
184 # this purpose. First install nginx and php-fpm:
186 sudo apt install -y nginx php-fpm
188 # You need to configure php-fpm to listen on a Unix socket.
191 sudo tee /etc/php/7.4/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
193 ; Replace the tcp listener and add the unix socket
194 listen = /var/run/php7.4-fpm.sock
196 ; Ensure that the daemon runs as the correct user
197 listen.owner = www-data
198 listen.group = www-data
201 ; Unix user of FPM processes
205 ; Choose process manager type (static, dynamic, ondemand)
211 # Then create a Nginx configuration to forward http requests to that socket.
214 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
216 listen 80 default_server;
217 listen [::]:80 default_server;
219 root $USERHOME/nominatim-project/website;
220 index search.php index.html;
222 try_files \$uri \$uri/ @php;
226 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
227 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
228 fastcgi_param QUERY_STRING \$args;
229 fastcgi_pass unix:/var/run/php7.4-fpm.sock;
230 fastcgi_index index.php;
231 include fastcgi_params;
234 location ~ [^/]\.php(/|$) {
235 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
236 if (!-f \$document_root\$fastcgi_script_name) {
239 fastcgi_pass unix:/var/run/php7.4-fpm.sock;
240 fastcgi_index search.php;
241 include fastcgi.conf;
248 # Enable the configuration and restart Nginx
251 sudo systemctl restart php7.4-fpm nginx
253 # The Nominatim API is now available at `http://localhost/`.