]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-18.sh
move SearchDescription building into tokens
[nominatim.git] / vagrant / Install-on-Ubuntu-18.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 #
10 # *Note:* these installation instructions are also available in executable
11 #         form for use with vagrant under vagrant/Install-on-Ubuntu-18.sh.
12 #
13 # Installing the Required Software
14 # ================================
15 #
16 # These instructions expect that you have a freshly installed Ubuntu 18.04.
17 #
18 # Make sure all packages are are up-to-date by running:
19 #
20
21     sudo apt-get -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" --force-yes -fuy install grub-pc #DOCS:
22     sudo apt update -qq
23
24 # Now you can install all packages needed for Nominatim:
25
26     sudo apt install -y php-cgi
27     sudo apt install -y build-essential cmake g++ libboost-dev libboost-system-dev \
28                         libboost-filesystem-dev libexpat1-dev zlib1g-dev\
29                         libbz2-dev libpq-dev libproj-dev \
30                         postgresql-server-dev-10 postgresql-10-postgis-2.4 \
31                         postgresql-contrib-10 postgresql-10-postgis-scripts \
32                         php php-pgsql php-intl libicu-dev python3-pip \
33                         python3-psycopg2 python3-psutil python3-jinja2 python3-icu git
34
35 # Some of the Python packages that come with Ubuntu 18.04 are too old, so
36 # install the latest version from pip:
37
38     pip3 install python-dotenv datrie pyyaml
39
40 #
41 # System Configuration
42 # ====================
43 #
44 # The following steps are meant to configure a fresh Ubuntu installation
45 # for use with Nominatim. You may skip some of the steps if you have your
46 # OS already configured.
47 #
48 # Creating Dedicated User Accounts
49 # --------------------------------
50 #
51 # Nominatim will run as a global service on your machine. It is therefore
52 # best to install it under its own separate user account. In the following
53 # we assume this user is called nominatim and the installation will be in
54 # /srv/nominatim. To create the user and directory run:
55 #
56 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
57 #
58 # You may find a more suitable location if you wish.
59 #
60 # To be able to copy and paste instructions from this manual, export
61 # user name and home directory now like this:
62 #
63     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
64     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
65 #
66 # **Never, ever run the installation as a root user.** You have been warned.
67 #
68 # Make sure that system servers can read from the home directory:
69
70     chmod a+x $USERHOME
71
72 # Setting up PostgreSQL
73 # ---------------------
74 #
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.
79 #
80 # Restart the postgresql service after updating this config file.
81
82     sudo systemctl restart postgresql
83
84 #
85 # Finally, we need to add two postgres users: one for the user that does
86 # the import and another for the webserver which should access the database
87 # for reading only:
88 #
89
90     sudo -u postgres createuser -s $USERNAME
91     sudo -u postgres createuser www-data
92
93 #
94 # Installing Nominatim
95 # ====================
96 #
97 # Building and Configuration
98 # --------------------------
99 #
100 # Get the source code from Github and change into the source directory
101 #
102 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
103     cd $USERHOME
104     git clone --recursive git://github.com/openstreetmap/Nominatim.git
105     cd Nominatim
106 else                               #DOCS:
107     cd $USERHOME/Nominatim         #DOCS:
108 fi                                 #DOCS:
109
110 # When installing the latest source from github, you also need to
111 # download the country grid:
112
113 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
114     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
115 fi                                 #DOCS:
116
117 # The code must be built in a separate directory. Create this directory,
118 # then configure and build Nominatim in there:
119
120     mkdir $USERHOME/build
121     cd $USERHOME/build
122     cmake $USERHOME/Nominatim
123     make
124     sudo make install
125
126
127 # Nominatim is now ready to use. You can continue with
128 # [importing a database from OSM data](../admin/Import.md). If you want to set up
129 # a webserver first, continue reading.
130 #
131 # Setting up a webserver
132 # ======================
133 #
134 # The webserver should serve the php scripts from the website directory of your
135 # [project directory](../admin/Import.md#creating-the-project-directory).
136 # Therefore set up a project directory and populate the website directory:
137
138     mkdir $USERHOME/nominatim-project
139     cd $USERHOME/nominatim-project
140     nominatim refresh --website
141 #
142 # Option 1: Using Apache
143 # ----------------------
144 #
145 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
146 #
147 # Apache has a PHP module that can be used to serve Nominatim. To install them
148 # run:
149
150     sudo apt install -y apache2 libapache2-mod-php
151
152 # You need to create an alias to the website directory in your apache
153 # configuration. Add a separate nominatim configuration to your webserver:
154
155 #DOCS:```sh
156 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
157 <Directory "$USERHOME/nominatim-project/website">
158   Options FollowSymLinks MultiViews
159   AddType text/html   .php
160   DirectoryIndex search.php
161   Require all granted
162 </Directory>
163
164 Alias /nominatim $USERHOME/nominatim-project/website
165 EOFAPACHECONF
166 #DOCS:```
167
168 #
169 # Then enable the configuration and restart apache
170 #
171
172     sudo a2enconf nominatim
173     sudo systemctl restart apache2
174
175 # The Nominatim API is now available at `http://localhost/nominatim/`.
176
177 fi   #DOCS:
178
179 #
180 # Option 2: Using nginx
181 # ---------------------
182 #
183 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
184
185 # Nginx has no native support for php scripts. You need to set up php-fpm for
186 # this purpose. First install nginx and php-fpm:
187
188     sudo apt install -y nginx php-fpm
189
190 # You need to configure php-fpm to listen on a Unix socket.
191
192 #DOCS:```sh
193 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
194 [www]
195 ; Replace the tcp listener and add the unix socket
196 listen = /var/run/php7.2-fpm.sock
197
198 ; Ensure that the daemon runs as the correct user
199 listen.owner = www-data
200 listen.group = www-data
201 listen.mode = 0666
202
203 ; Unix user of FPM processes
204 user = www-data
205 group = www-data
206
207 ; Choose process manager type (static, dynamic, ondemand)
208 pm = ondemand
209 pm.max_children = 5
210 EOF_PHP_FPM_CONF
211 #DOCS:```
212
213 # Then create a Nginx configuration to forward http requests to that socket.
214
215 #DOCS:```sh
216 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
217 server {
218     listen 80 default_server;
219     listen [::]:80 default_server;
220
221     root $USERHOME/nominatim-project/website;
222     index search.php index.html;
223     location / {
224         try_files \$uri \$uri/ @php;
225     }
226
227     location @php {
228         fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
229         fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
230         fastcgi_param QUERY_STRING    \$args;
231         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
232         fastcgi_index index.php;
233         include fastcgi_params;
234     }
235
236     location ~ [^/]\.php(/|$) {
237         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
238         if (!-f \$document_root\$fastcgi_script_name) {
239             return 404;
240         }
241         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
242         fastcgi_index search.php;
243         include fastcgi.conf;
244     }
245 }
246 EOF_NGINX_CONF
247 #DOCS:```
248
249 #
250 # Enable the configuration and restart Nginx
251 #
252
253     sudo systemctl restart php7.2-fpm nginx
254
255 # The Nominatim API is now available at `http://localhost/`.
256
257
258
259 fi   #DOCS: