]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-20.sh
Merge pull request #1962 from mtmail/travis-ci-without-webserver
[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-get update -qq
26
27 # Now you can install all packages needed for Nominatim:
28
29     sudo apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
30                             libboost-filesystem-dev libexpat1-dev zlib1g-dev \
31                             libbz2-dev libpq-dev libproj-dev \
32                             postgresql-server-dev-12 postgresql-12-postgis-3 \
33                             postgresql-contrib postgresql-12-postgis-3-scripts \
34                             apache2 php php-pgsql libapache2-mod-php \
35                             php-intl python3-setuptools python3-dev python3-pip \
36                             python3-psycopg2 python3-tidylib git
37
38 #
39 # System Configuration
40 # ====================
41 #
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.
45 #
46 # Creating Dedicated User Accounts
47 # --------------------------------
48 #
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:
53 #
54 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
55 #
56 # You may find a more suitable location if you wish.
57 #
58 # To be able to copy and paste instructions from this manual, export
59 # user name and home directory now like this:
60 #
61     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
62     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
63 #
64 # **Never, ever run the installation as a root user.** You have been warned.
65 #
66 # Make sure that system servers can read from the home directory:
67
68     chmod a+x $USERHOME
69
70 # Setting up PostgreSQL
71 # ---------------------
72 #
73 # Tune the postgresql configuration, which is located in 
74 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
75 # [the installation page](../admin/Installation.md#postgresql-tuning)
76 # for the parameters to change.
77 #
78 # Restart the postgresql service after updating this config file.
79
80     sudo systemctl restart postgresql
81
82 #
83 # Finally, we need to add two postgres users: one for the user that does
84 # the import and another for the webserver which should access the database
85 # for reading only:
86 #
87
88     sudo -u postgres createuser -s $USERNAME
89     sudo -u postgres createuser www-data
90
91 #
92 # Setting up the Apache Webserver
93 # -------------------------------
94 #
95 # You need to create an alias to the website directory in your apache
96 # configuration. Add a separate nominatim configuration to your webserver:
97
98 #DOCS:```sh
99 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
100 <Directory "$USERHOME/build/website"> #DOCS:<Directory "$USERHOME/Nominatim/build/website">
101   Options FollowSymLinks MultiViews
102   AddType text/html   .php
103   DirectoryIndex search.php
104   Require all granted
105 </Directory>
106
107 Alias /nominatim $USERHOME/build/website  #DOCS:Alias /nominatim $USERHOME/Nominatim/build/website
108 EOFAPACHECONF
109 #DOCS:```
110
111 sudo sed -i 's:#.*::' /etc/apache2/conf-available/nominatim.conf #DOCS:
112
113 #
114 # Then enable the configuration and restart apache
115 #
116
117     sudo a2enconf nominatim
118     sudo systemctl restart apache2
119
120 #
121 # Installing Nominatim
122 # ====================
123 #
124 # Building and Configuration
125 # --------------------------
126 #
127 # Get the source code from Github and change into the source directory
128 #
129 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
130     cd $USERHOME
131     git clone --recursive git://github.com/openstreetmap/Nominatim.git
132     cd Nominatim
133 else                               #DOCS:
134     cd $USERHOME/Nominatim         #DOCS:
135 fi                                 #DOCS:
136
137 # When installing the latest source from github, you also need to
138 # download the country grid:
139
140 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
141     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
142 fi                                 #DOCS:
143
144 # The code must be built in a separate directory. Create this directory,
145 # then configure and build Nominatim in there:
146
147     cd $USERHOME                   #DOCS:    :::sh
148     mkdir build
149     cd build
150     cmake $USERHOME/Nominatim
151     make
152
153 # You need to create a minimal configuration file that tells nominatim
154 # where it is located on the webserver:
155
156 #DOCS:```sh
157 tee settings/local.php << EOF
158 <?php
159  @define('CONST_Website_BaseURL', '/nominatim/');
160 EOF
161 #DOCS:```
162
163
164 # Nominatim is now ready to use. Continue with
165 # [importing a database from OSM data](../admin/Import.md).