]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Centos-8.sh
introduce sanitizer step before token analysis
[nominatim.git] / vagrant / Install-on-Centos-8.sh
1 #!/bin/bash -ex
2 #
3 # *Note:* these installation instructions are also available in executable
4 #         form for use with vagrant under `vagrant/Install-on-Centos-8.sh`.
5 #
6 # Installing the Required Software
7 # ================================
8 #
9 # These instructions expect that you have a freshly installed CentOS version 8.
10 # Make sure all packages are up-to-date by running:
11 #
12     sudo dnf update -y
13
14 # The standard CentOS repositories don't contain all the required packages,
15 # you need to enable the EPEL repository as well. For example for SELinux
16 # related redhat-hardened-cc1 package. To enable it on CentOS run:
17
18     sudo dnf install -y epel-release redhat-rpm-config
19
20 # EPEL contains Postgres 9.6 and 10, but not PostGIS. Postgres 9.4+/10/11/12
21 # and PostGIS 2.4/2.5/3.0 are availble from postgresql.org. Enable these
22 # repositories and make sure, the binaries can be found:
23
24     sudo dnf -qy module disable postgresql
25     sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
26     export PATH=/usr/pgsql-12/bin:$PATH
27
28 # Now you can install all packages needed for Nominatim:
29
30 #DOCS:    :::sh
31     sudo dnf --enablerepo=powertools install -y postgresql12-server \
32                         postgresql12-contrib postgresql12-devel postgis30_12 \
33                         wget git cmake make gcc gcc-c++ libtool policycoreutils-python-utils \
34                         llvm-toolset ccache clang-tools-extra \
35                         php-pgsql php php-intl php-json libpq-devel \
36                         bzip2-devel proj-devel boost-devel \
37                         python3-pip python3-setuptools python3-devel \
38                         python3-psycopg2 \
39                         expat-devel zlib-devel libicu-devel
40
41     pip3 install --user python-dotenv psutil Jinja2 PyICU datrie pyyaml
42
43
44 #
45 # System Configuration
46 # ====================
47 #
48 # The following steps are meant to configure a fresh CentOS installation
49 # for use with Nominatim. You may skip some of the steps if you have your
50 # OS already configured.
51 #
52 # Creating Dedicated User Accounts
53 # --------------------------------
54 #
55 # Nominatim will run as a global service on your machine. It is therefore
56 # best to install it under its own separate user account. In the following
57 # we assume this user is called nominatim and the installation will be in
58 # /srv/nominatim. To create the user and directory run:
59 #
60 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
61 #
62 # You may find a more suitable location if you wish.
63 #
64 # To be able to copy and paste instructions from this manual, export
65 # user name and home directory now like this:
66 #
67 if [ "x$USERNAME" == "x" ]; then       #DOCS:
68     export USERNAME=vagrant            #DOCS:    export USERNAME=nominatim
69     export USERHOME=/srv/nominatim
70     sudo mkdir -p /srv/nominatim       #DOCS:
71     sudo chown vagrant /srv/nominatim  #DOCS:
72 fi                                     #DOCS:
73 #
74 # **Never, ever run the installation as a root user.** You have been warned.
75 #
76 # Make sure that system servers can read from the home directory:
77
78     chmod a+x $USERHOME
79
80 # Setting up PostgreSQL
81 # ---------------------
82 #
83 # CentOS does not automatically create a database cluster. Therefore, start
84 # with initializing the database:
85
86 if [ "x$NOSYSTEMD" == "xyes" ]; then                               #DOCS:
87     sudo -u postgres /usr/pgsql-12/bin/pg_ctl initdb -D /var/lib/pgsql/12/data     #DOCS:
88     sudo mkdir /var/log/postgresql                                 #DOCS:
89     sudo chown postgres. /var/log/postgresql                       #DOCS:
90 else                                                               #DOCS:
91     sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
92 fi                                                                 #DOCS:
93 #
94 # Next tune the postgresql configuration, which is located in
95 # `/var/lib/pgsql/12/data/postgresql.conf`. See section *Postgres Tuning* in
96 # [the installation page](../admin/Installation.md#postgresql-tuning)
97 # for the parameters to change.
98 #
99 # Now start the postgresql service after updating this config file:
100
101 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
102     sudo -u postgres /usr/pgsql-12/bin/pg_ctl -D /var/lib/pgsql/12/data -l /var/log/postgresql/postgresql-12.log start  #DOCS:
103 else                                  #DOCS:
104     sudo systemctl enable postgresql-12
105     sudo systemctl restart postgresql-12
106 fi                                    #DOCS:
107
108 #
109 # Finally, we need to add two postgres users: one for the user that does
110 # the import and another for the webserver which should access the database
111 # only for reading:
112 #
113
114     sudo -u postgres createuser -s $USERNAME
115     sudo -u postgres createuser apache
116
117 #
118 # Installing Nominatim
119 # ====================
120 #
121 # Building and Configuration
122 # --------------------------
123 #
124 # Get the source code from Github and change into the source directory
125 #
126 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
127     cd $USERHOME
128     git clone --recursive git://github.com/openstreetmap/Nominatim.git
129     cd Nominatim
130 else                               #DOCS:
131     cd $USERHOME/Nominatim         #DOCS:
132 fi                                 #DOCS:
133
134 # When installing the latest source from github, you also need to
135 # download the country grid:
136
137 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
138     wget --no-verbose -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
139 fi                                 #DOCS:
140
141 # The code must be built in a separate directory. Create this directory,
142 # then configure and build Nominatim in there:
143
144 #DOCS:    :::sh
145     mkdir $USERHOME/build
146     cd $USERHOME/build
147     cmake $USERHOME/Nominatim
148     make
149     sudo make install
150
151 #
152 # Setting up the Apache Webserver
153 # -------------------------------
154 #
155 # The webserver should serve the php scripts from the website directory of your
156 # [project directory](../admin/Import.md#creating-the-project-directory).
157 # This directory needs to exist when the webserver is configured.
158 # Therefore set up a project directory and create the website directory:
159 #
160     mkdir $USERHOME/nominatim-project
161     mkdir $USERHOME/nominatim-project/website
162 #
163 # You need to create an alias to the website directory in your apache
164 # configuration. Add a separate nominatim configuration to your webserver:
165
166 #DOCS:```sh
167 sudo tee /etc/httpd/conf.d/nominatim.conf << EOFAPACHECONF
168 <Directory "$USERHOME/nominatim-project/website">
169   Options FollowSymLinks MultiViews
170   AddType text/html   .php
171   DirectoryIndex search.php
172   Require all granted
173 </Directory>
174
175 Alias /nominatim $USERHOME/nominatim-project/website
176 EOFAPACHECONF
177 #DOCS:```
178
179 sudo sed -i 's:#.*::' /etc/httpd/conf.d/nominatim.conf #DOCS:
180
181 #
182 # Then reload apache:
183 #
184
185 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
186     sudo httpd                        #DOCS:
187 else                                  #DOCS:
188     sudo systemctl enable httpd
189     sudo systemctl restart httpd
190 fi                                    #DOCS:
191
192 #
193 # Adding SELinux Security Settings
194 # --------------------------------
195 #
196 # It is a good idea to leave SELinux enabled and enforcing, particularly
197 # with a web server accessible from the Internet. At a minimum the
198 # following SELinux labeling should be done for Nominatim:
199
200 if [ "x$HAVE_SELINUX" != "xno" ]; then  #DOCS:
201     sudo semanage fcontext -a -t httpd_sys_content_t "/usr/local/nominatim/lib/lib-php(/.*)?"
202     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/nominatim-project/website(/.*)?"
203     sudo semanage fcontext -a -t lib_t "$USERHOME/nominatim-project/module/nominatim.so"
204     sudo restorecon -R -v /usr/local/lib/nominatim
205     sudo restorecon -R -v $USERHOME/nominatim-project
206 fi                                 #DOCS:
207
208 # You need to create a minimal configuration file that tells nominatim
209 # the name of your webserver user:
210
211 #DOCS:```sh
212 echo NOMINATIM_DATABASE_WEBUSER="apache" | tee $USERHOME/nominatim-project/.env
213 #DOCS:```
214
215
216 # Nominatim is now ready to use. Continue with
217 # [importing a database from OSM data](../admin/Import.md).