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:
9 # *Note:* these installation instructions are also available in executable
10 # form for use with vagrant under vagrant/Install-on-Ubuntu-18.sh.
12 # Installing the Required Software
13 # ================================
15 # These instructions expect that you have a freshly installed Ubuntu 18.04.
17 # Make sure all packages are up-to-date by running:
22 # Now you can install all packages needed for Nominatim:
24 sudo apt install -y php-cgi
25 sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
26 libboost-filesystem-dev libexpat1-dev zlib1g-dev\
27 libbz2-dev libpq-dev libproj-dev \
28 postgresql-server-dev-10 postgresql-10-postgis-2.4 \
29 postgresql-contrib-10 postgresql-10-postgis-scripts \
30 php php-pgsql php-intl libicu-dev python3-pip \
31 python3-psutil python3-jinja2 python3-icu git
33 # Some of the Python packages that come with Ubuntu 18.04 are too old, so
34 # install the latest version from pip:
36 pip3 install --user python-dotenv datrie pyyaml psycopg2
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 if [ "x$USERNAME" == "x" ]; then #DOCS:
62 export USERNAME=vagrant #DOCS: export USERNAME=nominatim
63 export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
66 # **Never, ever run the installation as a root user.** You have been warned.
68 # Make sure that system servers can read from the home directory:
72 # Setting up PostgreSQL
73 # ---------------------
75 # Tune the postgresql configuration, which is located in
76 # `/etc/postgresql/10/main/postgresql.conf`. See section *Postgres Tuning* in
77 # [the installation page](../admin/Installation.md#postgresql-tuning)
78 # for the parameters to change.
80 # Restart the postgresql service after updating this config file.
82 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
83 sudo pg_ctlcluster 10 main start
85 sudo systemctl restart postgresql #DOCS:
89 # Finally, we need to add two postgres users: one for the user that does
90 # the import and another for the webserver which should access the database
94 sudo -u postgres createuser -s $USERNAME
95 sudo -u postgres createuser www-data
98 # Installing Nominatim
99 # ====================
101 # Building and Configuration
102 # --------------------------
104 # Get the source code from Github and change into the source directory
106 if [ "x$1" == "xyes" ]; then #DOCS: :::sh
108 git clone --recursive git://github.com/openstreetmap/Nominatim.git
111 cd $USERHOME/Nominatim #DOCS:
114 # When installing the latest source from github, you also need to
115 # download the country grid:
117 if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
118 wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
121 # The code must be built in a separate directory. Create this directory,
122 # then configure and build Nominatim in there:
124 mkdir $USERHOME/build
126 cmake $USERHOME/Nominatim
131 # Nominatim is now ready to use. You can continue with
132 # [importing a database from OSM data](../admin/Import.md). If you want to set up
133 # a webserver first, continue reading.
135 # Setting up a webserver
136 # ======================
138 # The webserver should serve the php scripts from the website directory of your
139 # [project directory](../admin/Import.md#creating-the-project-directory).
140 # This directory needs to exist when being configured.
141 # Therefore set up a project directory and create the website directory:
143 mkdir $USERHOME/nominatim-project
144 mkdir $USERHOME/nominatim-project/website
146 # The import process will populate the directory later.
148 # Option 1: Using Apache
149 # ----------------------
151 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
153 # Apache has a PHP module that can be used to serve Nominatim. To install them
156 sudo apt install -y apache2 libapache2-mod-php
158 # You need to create an alias to the website directory in your apache
159 # configuration. Add a separate nominatim configuration to your webserver:
162 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
163 <Directory "$USERHOME/nominatim-project/website">
164 Options FollowSymLinks MultiViews
165 AddType text/html .php
166 DirectoryIndex search.php
170 Alias /nominatim $USERHOME/nominatim-project/website
175 # Then enable the configuration and restart apache
178 sudo a2enconf nominatim
179 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
180 sudo apache2ctl start #DOCS:
182 sudo systemctl restart apache2
185 # The Nominatim API is now available at `http://localhost/nominatim/`.
190 # Option 2: Using nginx
191 # ---------------------
193 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
195 # Nginx has no native support for php scripts. You need to set up php-fpm for
196 # this purpose. First install nginx and php-fpm:
198 sudo apt install -y nginx php-fpm
200 # You need to configure php-fpm to listen on a Unix socket.
203 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
205 ; Replace the tcp listener and add the unix socket
206 listen = /var/run/php7.2-fpm.sock
208 ; Ensure that the daemon runs as the correct user
209 listen.owner = www-data
210 listen.group = www-data
213 ; Unix user of FPM processes
217 ; Choose process manager type (static, dynamic, ondemand)
223 # Then create a Nginx configuration to forward http requests to that socket.
226 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
228 listen 80 default_server;
229 listen [::]:80 default_server;
231 root $USERHOME/nominatim-project/website;
232 index search.php index.html;
234 try_files \$uri \$uri/ @php;
238 fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
239 fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
240 fastcgi_param QUERY_STRING \$args;
241 fastcgi_pass unix:/var/run/php7.2-fpm.sock;
242 fastcgi_index index.php;
243 include fastcgi_params;
246 location ~ [^/]\.php(/|$) {
247 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
248 if (!-f \$document_root\$fastcgi_script_name) {
251 fastcgi_pass unix:/var/run/php7.2-fpm.sock;
252 fastcgi_index search.php;
253 include fastcgi.conf;
260 # Enable the configuration and restart Nginx
263 if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
264 sudo /usr/sbin/php-fpm7.2 --nodaemonize --fpm-config /etc/php/7.2/fpm/php-fpm.conf & #DOCS:
265 sudo /usr/sbin/nginx & #DOCS:
267 sudo systemctl restart php7.2-fpm nginx
270 # The Nominatim API is now available at `http://localhost/`.