]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-18.sh
Merge pull request #1961 from lonvia/set-place-type-for-result-in-address
[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 \
33                         python3-psycopg2 git
34
35
36 #
37 # System Configuration
38 # ====================
39 #
40 # The following steps are meant to configure a fresh Ubuntu installation
41 # for use with Nominatim. You may skip some of the steps if you have your
42 # OS already configured.
43 #
44 # Creating Dedicated User Accounts
45 # --------------------------------
46 #
47 # Nominatim will run as a global service on your machine. It is therefore
48 # best to install it under its own separate user account. In the following
49 # we assume this user is called nominatim and the installation will be in
50 # /srv/nominatim. To create the user and directory run:
51 #
52 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
53 #
54 # You may find a more suitable location if you wish.
55 #
56 # To be able to copy and paste instructions from this manual, export
57 # user name and home directory now like this:
58 #
59     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
60     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
61 #
62 # **Never, ever run the installation as a root user.** You have been warned.
63 #
64 # Make sure that system servers can read from the home directory:
65
66     chmod a+x $USERHOME
67
68 # Setting up PostgreSQL
69 # ---------------------
70 #
71 # Tune the postgresql configuration, which is located in 
72 # `/etc/postgresql/10/main/postgresql.conf`. See section *Postgres Tuning* in
73 # [the installation page](../admin/Installation.md#postgresql-tuning)
74 # for the parameters to change.
75 #
76 # Restart the postgresql service after updating this config file.
77
78     sudo systemctl restart postgresql
79
80 #
81 # Finally, we need to add two postgres users: one for the user that does
82 # the import and another for the webserver which should access the database
83 # for reading only:
84 #
85
86     sudo -u postgres createuser -s $USERNAME
87     sudo -u postgres createuser www-data
88
89 #
90 # Installing Nominatim
91 # ====================
92 #
93 # Building and Configuration
94 # --------------------------
95 #
96 # Get the source code from Github and change into the source directory
97 #
98 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
99     cd $USERHOME
100     git clone --recursive git://github.com/openstreetmap/Nominatim.git
101     cd Nominatim
102 else                               #DOCS:
103     cd $USERHOME/Nominatim         #DOCS:
104 fi                                 #DOCS:
105
106 # When installing the latest source from github, you also need to
107 # download the country grid:
108
109 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
110     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
111 fi                                 #DOCS:
112
113 # The code must be built in a separate directory. Create this directory,
114 # then configure and build Nominatim in there:
115
116     cd $USERHOME
117     mkdir build
118     cd build
119     cmake $USERHOME/Nominatim
120     make
121
122
123 # Nominatim is now ready to use. You can continue with
124 # [importing a database from OSM data](../admin/Import.md). If you want to set up
125 # a webserver first, continue reading.
126 #
127 # Setting up a webserver
128 # ======================
129 #
130 # Option 1: Using Apache
131 # ----------------------
132 #
133 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
134 #
135 # Apache has a PHP module that can be used to serve Nominatim. To install them
136 # run:
137
138     sudo apt install -y apache2 libapache2-mod-php
139
140 # You need to create an alias to the website directory in your apache
141 # configuration. Add a separate nominatim configuration to your webserver:
142
143 #DOCS:```sh
144 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
145 <Directory "$USERHOME/build/website">
146   Options FollowSymLinks MultiViews
147   AddType text/html   .php
148   DirectoryIndex search.php
149   Require all granted
150 </Directory>
151
152 Alias /nominatim $USERHOME/build/website
153 EOFAPACHECONF
154 #DOCS:```
155
156 #
157 # Then enable the configuration and restart apache
158 #
159
160     sudo a2enconf nominatim
161     sudo systemctl restart apache2
162
163 # You need to create a minimal configuration file that tells nominatim
164 # where it is located on the webserver:
165
166 #DOCS:```sh
167 tee settings/local.php << EOF
168 <?php
169  @define('CONST_Website_BaseURL', '/nominatim/');
170 EOF
171 #DOCS:```
172
173 # The Nominatim API is now available at `http://localhost/nominatim/`.
174
175 fi   #DOCS:
176
177 #
178 # Option 2: Using nginx
179 # ---------------------
180 #
181 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
182
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:
185
186     sudo apt install -y nginx php-fpm
187
188 # You need to configure php-fpm to listen on a Unix socket.
189
190 #DOCS:```sh
191 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
192 [www]
193 ; Replace the tcp listener and add the unix socket
194 listen = /var/run/php7.2-fpm.sock
195
196 ; Ensure that the daemon runs as the correct user
197 listen.owner = www-data
198 listen.group = www-data
199 listen.mode = 0666
200
201 ; Unix user of FPM processes
202 user = www-data
203 group = www-data
204
205 ; Choose process manager type (static, dynamic, ondemand)
206 pm = ondemand
207 pm.max_children = 5
208 EOF_PHP_FPM_CONF
209 #DOCS:```
210
211 # Then create a Nginx configuration to forward http requests to that socket.
212
213 #DOCS:```sh
214 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
215 server {
216     listen 80 default_server;
217     listen [::]:80 default_server;
218
219     root $USERHOME/build/website;
220     index search.php index.html;
221     location / {
222         try_files \$uri \$uri/ @php;
223     }
224
225     location @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.2-fpm.sock;
230         fastcgi_index index.php;
231         include fastcgi_params;
232     }
233
234     location ~ [^/]\.php(/|$) {
235         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
236         if (!-f \$document_root\$fastcgi_script_name) {
237             return 404;
238         }
239         fastcgi_pass unix:/var/run/php7.2-fpm.sock;
240         fastcgi_index search.php;
241         include fastcgi.conf;
242     }
243 }
244 EOF_NGINX_CONF
245 #DOCS:```
246
247 #
248 # Enable the configuration and restart Nginx
249 #
250
251     sudo systemctl restart php7.2-fpm nginx
252
253 # The Nominatim API is now available at `http://localhost/`.
254
255
256
257 fi   #DOCS: