]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-20.sh
85a95c9b4a268e9c4442d212eb06e7183ad244f6
[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 #
10 # *Note:* these installation instructions are also available in executable
11 #         form for use with vagrant under vagrant/Install-on-Ubuntu-20.sh.
12 #
13 # Installing the Required Software
14 # ================================
15 #
16 # These instructions expect that you have a freshly installed Ubuntu 20.04.
17 #
18 # Make sure all packages are are up-to-date by running:
19 #
20
21 #DOCS:    :::sh
22     sudo apt-get \
23         -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" \
24         --allow-downgrades --allow-remove-essential --allow-change-held-packages \
25         -fuy install grub-pc #DOCS:
26     sudo apt-get update -qq
27
28 # Now you can install all packages needed for Nominatim:
29
30     sudo apt-get 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 postgresql-12-postgis-3-scripts \
35                             apache2 php php-pgsql libapache2-mod-php \
36                             php-intl python3-setuptools python3-dev python3-pip \
37                             python3-psycopg2 python3-tidylib git
38
39 # If you want to run the test suite, you need to install the following
40 # additional packages:
41
42     sudo apt-get install -y phpunit php-codesniffer php-cgi
43
44     pip3 install --user behave nose
45 #
46 # System Configuration
47 # ====================
48 #
49 # The following steps are meant to configure a fresh Ubuntu installation
50 # for use with Nominatim. You may skip some of the steps if you have your
51 # OS already configured.
52 #
53 # Creating Dedicated User Accounts
54 # --------------------------------
55 #
56 # Nominatim will run as a global service on your machine. It is therefore
57 # best to install it under its own separate user account. In the following
58 # we assume this user is called nominatim and the installation will be in
59 # /srv/nominatim. To create the user and directory run:
60 #
61 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
62 #
63 # You may find a more suitable location if you wish.
64 #
65 # To be able to copy and paste instructions from this manual, export
66 # user name and home directory now like this:
67 #
68     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
69     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
70 #
71 # **Never, ever run the installation as a root user.** You have been warned.
72 #
73 # Make sure that system servers can read from the home directory:
74
75     chmod a+x $USERHOME
76
77 # Setting up PostgreSQL
78 # ---------------------
79 #
80 # Tune the postgresql configuration, which is located in 
81 # `/etc/postgresql/12/main/postgresql.conf`. See section *Postgres Tuning* in
82 # [the installation page](../admin/Installation.md#postgresql-tuning)
83 # for the parameters to change.
84 #
85 # Restart the postgresql service after updating this config file.
86
87     sudo systemctl restart postgresql
88
89 #
90 # Finally, we need to add two postgres users: one for the user that does
91 # the import and another for the webserver which should access the database
92 # for reading only:
93 #
94
95     sudo -u postgres createuser -s $USERNAME
96     sudo -u postgres createuser www-data
97
98 #
99 # Setting up the Apache Webserver
100 # -------------------------------
101 #
102 # You need to create an alias to the website directory in your apache
103 # configuration. Add a separate nominatim configuration to your webserver:
104
105 #DOCS:```sh
106 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
107 <Directory "$USERHOME/build/website"> #DOCS:<Directory "$USERHOME/Nominatim/build/website">
108   Options FollowSymLinks MultiViews
109   AddType text/html   .php
110   DirectoryIndex search.php
111   Require all granted
112 </Directory>
113
114 Alias /nominatim $USERHOME/build/website  #DOCS:Alias /nominatim $USERHOME/Nominatim/build/website
115 EOFAPACHECONF
116 #DOCS:```
117
118 sudo sed -i 's:#.*::' /etc/apache2/conf-available/nominatim.conf #DOCS:
119
120 #
121 # Then enable the configuration and restart apache
122 #
123
124     sudo a2enconf nominatim
125     sudo systemctl restart apache2
126
127 #
128 # Installing Nominatim
129 # ====================
130 #
131 # Building and Configuration
132 # --------------------------
133 #
134 # Get the source code from Github and change into the source directory
135 #
136 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
137     cd $USERHOME
138     git clone --recursive git://github.com/openstreetmap/Nominatim.git
139     cd Nominatim
140 else                               #DOCS:
141     cd $USERHOME/Nominatim         #DOCS:
142 fi                                 #DOCS:
143
144 # When installing the latest source from github, you also need to
145 # download the country grid:
146
147 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
148     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
149 fi                                 #DOCS:
150
151 # The code must be built in a separate directory. Create this directory,
152 # then configure and build Nominatim in there:
153
154     cd $USERHOME                   #DOCS:    :::sh
155     mkdir build
156     cd build
157     cmake $USERHOME/Nominatim
158     make
159
160 # You need to create a minimal configuration file that tells nominatim
161 # where it is located on the webserver:
162
163 #DOCS:```sh
164 tee settings/local.php << EOF
165 <?php
166  @define('CONST_Website_BaseURL', '/nominatim/');
167 EOF
168 #DOCS:```
169
170
171 # Nominatim is now ready to use. Continue with
172 # [importing a database from OSM data](../admin/Import-and-Update.md).