]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-20.sh
move SearchDescription building into tokens
[nominatim.git] / vagrant / Install-on-Ubuntu-20.sh
1 #!/bin/bash
2 #
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:
8
9 # *Note:* these installation instructions are also available in executable
10 #         form for use with vagrant under vagrant/Install-on-Ubuntu-20.sh.
11 #
12 # Installing the Required Software
13 # ================================
14 #
15 # These instructions expect that you have a freshly installed Ubuntu 20.04.
16 #
17 # Make sure all packages are are up-to-date by running:
18 #
19
20 #DOCS:    :::sh
21     sudo apt-get \ #DOCS:
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:
25     sudo apt update -qq
26
27 # Now you can install all packages needed for Nominatim:
28
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
38
39 #
40 # System Configuration
41 # ====================
42 #
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.
46 #
47 # Creating Dedicated User Accounts
48 # --------------------------------
49 #
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:
54 #
55 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
56 #
57 # You may find a more suitable location if you wish.
58 #
59 # To be able to copy and paste instructions from this manual, export
60 # user name and home directory now like this:
61 #
62     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
63     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
64 #
65 # **Never, ever run the installation as a root user.** You have been warned.
66 #
67 # Make sure that system servers can read from the home directory:
68
69     chmod a+x $USERHOME
70
71 # Setting up PostgreSQL
72 # ---------------------
73 #
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.
78 #
79 # Restart the postgresql service after updating this config file.
80
81     sudo systemctl restart postgresql
82
83 #
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
86 # for reading only:
87 #
88
89     sudo -u postgres createuser -s $USERNAME
90     sudo -u postgres createuser www-data
91
92 #
93 # Installing Nominatim
94 # ====================
95 #
96 # Building and Configuration
97 # --------------------------
98 #
99 # Get the source code from Github and change into the source directory
100 #
101 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
102     cd $USERHOME
103     git clone --recursive git://github.com/openstreetmap/Nominatim.git
104     cd Nominatim
105 else                               #DOCS:
106     cd $USERHOME/Nominatim         #DOCS:
107 fi                                 #DOCS:
108
109 # When installing the latest source from github, you also need to
110 # download the country grid:
111
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
114 fi                                 #DOCS:
115
116 # The code must be built in a separate directory. Create this directory,
117 # then configure and build Nominatim in there:
118
119     mkdir $USERHOME/build
120     cd $USERHOME/build
121     cmake $USERHOME/Nominatim
122     make
123     sudo make install
124
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.
128 #
129 # Setting up a webserver
130 # ======================
131 #
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:
135
136     mkdir $USERHOME/nominatim-project
137     cd $USERHOME/nominatim-project
138     nominatim refresh --website
139
140 #
141 # Option 1: Using Apache
142 # ----------------------
143 #
144 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
145 #
146 # Apache has a PHP module that can be used to serve Nominatim. To install them
147 # run:
148
149     sudo apt install -y apache2 libapache2-mod-php
150
151 # You need to create an alias to the website directory in your apache
152 # configuration. Add a separate nominatim configuration to your webserver:
153
154 #DOCS:```sh
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
160   Require all granted
161 </Directory>
162
163 Alias /nominatim $USERHOME/nominatim-project/website
164 EOFAPACHECONF
165 #DOCS:```
166
167 #
168 # Then enable the configuration and restart apache
169 #
170
171     sudo a2enconf nominatim
172     sudo systemctl restart apache2
173
174 # The Nominatim API is now available at `http://localhost/nominatim/`.
175
176 fi   #DOCS:
177
178 #
179 # Option 2: Using nginx
180 # ---------------------
181 #
182 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
183
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:
186
187     sudo apt install -y nginx php-fpm
188
189 # You need to configure php-fpm to listen on a Unix socket.
190
191 #DOCS:```sh
192 sudo tee /etc/php/7.4/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
193 [www]
194 ; Replace the tcp listener and add the unix socket
195 listen = /var/run/php7.4-fpm.sock
196
197 ; Ensure that the daemon runs as the correct user
198 listen.owner = www-data
199 listen.group = www-data
200 listen.mode = 0666
201
202 ; Unix user of FPM processes
203 user = www-data
204 group = www-data
205
206 ; Choose process manager type (static, dynamic, ondemand)
207 pm = ondemand
208 pm.max_children = 5
209 EOF_PHP_FPM_CONF
210 #DOCS:```
211
212 # Then create a Nginx configuration to forward http requests to that socket.
213
214 #DOCS:```sh
215 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
216 server {
217     listen 80 default_server;
218     listen [::]:80 default_server;
219
220     root $USERHOME/nominatim-project/website;
221     index search.php index.html;
222     location / {
223         try_files \$uri \$uri/ @php;
224     }
225
226     location @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;
233     }
234
235     location ~ [^/]\.php(/|$) {
236         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
237         if (!-f \$document_root\$fastcgi_script_name) {
238             return 404;
239         }
240         fastcgi_pass unix:/var/run/php7.4-fpm.sock;
241         fastcgi_index search.php;
242         include fastcgi.conf;
243     }
244 }
245 EOF_NGINX_CONF
246 #DOCS:```
247
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.
251 #
252 # Enable the configuration and restart Nginx
253 #
254
255     sudo systemctl restart php7.4-fpm nginx
256
257 # The Nominatim API is now available at `http://localhost/`.
258
259
260
261 fi   #DOCS: