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