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 libicu-dev python3-dotenv \
36 python3-psycopg2 python3-psutil python3-jinja2 \
37 python3-icu python3-datrie git
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 # To be able to copy and paste instructions from this manual, export
60 # user name and home directory now like this:
62 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
63 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
65 # **Never, ever run the installation as a root user.** You have been warned.
67 # Make sure that system servers can read from the home directory:
71 # Setting up PostgreSQL
72 # ---------------------
74 # Tune the postgresql configuration, which is located in
75 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
76 # [the installation page](../admin/Installation.md#postgresql-tuning)
77 # for the parameters to change.
79 # Restart the postgresql service after updating this config file.
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 git://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://www.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 # Therefore set up a project directory and populate the website directory:
136 mkdir $USERHOME/nominatim-project
137 cd $USERHOME/nominatim-project
138 nominatim refresh --website
141 # Option 1: Using Apache
142 # ----------------------
144 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
146 # Apache has a PHP module that can be used to serve Nominatim. To install them
149 sudo apt install -y apache2 libapache2-mod-php
151 # You need to create an alias to the website directory in your apache
152 # configuration. Add a separate nominatim configuration to your webserver:
155 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
156 <Directory "$USERHOME/nominatim-project/website">
157 Options FollowSymLinks MultiViews
158 AddType text/html .php
159 DirectoryIndex search.php
163 Alias /nominatim $USERHOME/nominatim-project/website
168 # Then enable the configuration and restart apache
171 sudo a2enconf nominatim
172 sudo systemctl restart apache2
174 # The Nominatim API is now available at `http://localhost/nominatim/`.
179 # Option 2: Using nginx
180 # ---------------------
182 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
184 # Nginx has no native support for php scripts. You need to set up php-fpm for
185 # this purpose. First install nginx and php-fpm:
187 sudo apt install -y nginx php-fpm
189 # You need to configure php-fpm to listen on a Unix socket.
192 sudo tee /etc/php/7.4/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
194 ; Replace the tcp listener and add the unix socket
195 listen = /var/run/php7.4-fpm.sock
197 ; Ensure that the daemon runs as the correct user
198 listen.owner = www-data
199 listen.group = www-data
202 ; Unix user of FPM processes
206 ; Choose process manager type (static, dynamic, ondemand)
212 # Then create a Nginx configuration to forward http requests to that socket.
215 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
217 listen 80 default_server;
218 listen [::]:80 default_server;
220 root $USERHOME/nominatim-project/website;
221 index search.php index.html;
223 try_files \$uri \$uri/ @php;
227 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
228 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
229 fastcgi_param QUERY_STRING \$args;
230 fastcgi_pass unix:/var/run/php7.4-fpm.sock;
231 fastcgi_index index.php;
232 include fastcgi_params;
235 location ~ [^/]\.php(/|$) {
236 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
237 if (!-f \$document_root\$fastcgi_script_name) {
240 fastcgi_pass unix:/var/run/php7.4-fpm.sock;
241 fastcgi_index search.php;
242 include fastcgi.conf;
248 # If you have some errors, make sure that php7.4-fpm.sock is well under
249 # /var/run/ and not under /var/run/php. Otherwise change the Nginx configuration
250 # to /var/run/php/php7.4-fpm.sock.
252 # Enable the configuration and restart Nginx
255 sudo systemctl restart php7.4-fpm nginx
257 # The Nominatim API is now available at `http://localhost/`.