]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Centos-8.sh
Merge pull request #1945 from mtmail/travis-ubuntu-20
[nominatim.git] / vagrant / Install-on-Centos-8.sh
1 #!/bin/bash
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
22
23     sudo dnf -qy module disable postgresql
24     sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
25
26 # Now you can install all packages needed for Nominatim:
27
28 #DOCS:    :::sh
29     sudo dnf --enablerepo=PowerTools install -y postgresql12-server \
30                         postgresql12-contrib postgresql12-devel postgis30_12 \
31                         wget git cmake make gcc gcc-c++ libtool policycoreutils-python-utils \
32                         llvm-toolset ccache clang-tools-extra \
33                         php-pgsql php php-intl php-json libpq-devel \
34                         bzip2-devel proj-devel boost-devel \
35                         python3-pip python3-setuptools python3-devel \
36                         expat-devel zlib-devel
37
38     # make sure pg_config gets found
39     echo 'PATH=/usr/pgsql-12/bin:$PATH' >> ~/.bash_profile
40     source ~/.bash_profile
41
42     pip3 install --user psycopg2 pytidylib
43
44
45 #
46 # System Configuration
47 # ====================
48 #
49 # The following steps are meant to configure a fresh CentOS 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 mkdir -p /srv/nominatim       #DOCS:    sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
62 sudo chown vagrant /srv/nominatim  #DOCS:
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=/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 # CentOS does not automatically create a database cluster. Therefore, start
82 # with initializing the database, then enable the server to start at boot:
83
84
85     sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
86     sudo systemctl enable postgresql-12
87
88 #
89 # Next tune the postgresql configuration, which is located in 
90 # `/var/lib/pgsql/data/postgresql.conf`. See section *Postgres Tuning* in
91 # [the installation page](../admin/Installation.md#postgresql-tuning)
92 # for the parameters to change.
93 #
94 # Now start the postgresql service after updating this config file.
95
96     sudo systemctl restart postgresql-12
97
98 #
99 # Finally, we need to add two postgres users: one for the user that does
100 # the import and another for the webserver which should access the database
101 # only for reading:
102 #
103
104     sudo -u postgres createuser -s $USERNAME
105     sudo -u postgres createuser apache
106
107 #
108 # Setting up the Apache Webserver
109 # -------------------------------
110 #
111 # You need to create an alias to the website directory in your apache
112 # configuration. Add a separate nominatim configuration to your webserver:
113
114 #DOCS:```sh
115 sudo tee /etc/httpd/conf.d/nominatim.conf << EOFAPACHECONF
116 <Directory "$USERHOME/build/website">
117   Options FollowSymLinks MultiViews
118   AddType text/html   .php
119   DirectoryIndex search.php
120   Require all granted
121 </Directory>
122
123 Alias /nominatim $USERHOME/build/website
124 EOFAPACHECONF
125 #DOCS:```
126
127 sudo sed -i 's:#.*::' /etc/httpd/conf.d/nominatim.conf #DOCS:
128
129 #
130 # Then reload apache
131 #
132
133     sudo systemctl enable httpd
134     sudo systemctl restart httpd
135
136
137 #
138 # Installing Nominatim
139 # ====================
140 #
141 # Building and Configuration
142 # --------------------------
143 #
144 # Get the source code from Github and change into the source directory
145 #
146 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
147     cd $USERHOME
148     git clone --recursive git://github.com/openstreetmap/Nominatim.git
149     cd Nominatim
150 else                               #DOCS:
151     cd $USERHOME/Nominatim         #DOCS:
152 fi                                 #DOCS:
153
154 # When installing the latest source from github, you also need to
155 # download the country grid:
156
157 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
158     wget --no-verbose -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
159 fi                                 #DOCS:
160
161 # The code must be built in a separate directory. Create this directory,
162 # then configure and build Nominatim in there:
163
164 #DOCS:    :::sh
165     cd $USERHOME
166     mkdir build
167     cd build
168     cmake $USERHOME/Nominatim
169     make
170
171 #
172 # Adding SELinux Security Settings
173 # --------------------------------
174 #
175 # It is a good idea to leave SELinux enabled and enforcing, particularly
176 # with a web server accessible from the Internet. At a minimum the
177 # following SELinux labeling should be done for Nominatim:
178
179     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/Nominatim/(website|lib|settings)(/.*)?"
180     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/build/(website|lib|settings)(/.*)?"
181     sudo semanage fcontext -a -t lib_t "$USERHOME/build/module/nominatim.so"
182     sudo restorecon -R -v $USERHOME/Nominatim
183     sudo restorecon -R -v $USERHOME/build
184
185
186 # You need to create a minimal configuration file that tells nominatim
187 # the name of your webserver user and the URL of the website:
188
189 #DOCS:```sh
190 tee settings/local.php << EOF
191 <?php
192  @define('CONST_Database_Web_User', 'apache');
193  @define('CONST_Website_BaseURL', '/nominatim/');
194 EOF
195 #DOCS:```
196
197
198 # Nominatim is now ready to use. Continue with
199 # [importing a database from OSM data](../admin/Import.md).