]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Centos-8.sh
Merge pull request #1780 from Simon-Will/1768-vagrant-installation-for-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 postgresql10-server \
30                         postgresql10-contrib postgresql10-devel postgis25_10 \
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                         proj52-epsg 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-10/bin:$PATH' >> ~/.bash_profile
40     source ~/.bash_profile
41
42     pip3 install --user psycopg2 pytidylib
43
44 # If you want to run the test suite, you need to install the following
45 # additional packages:
46
47 #DOCS:    :::sh
48     sudo dnf install -y php-dom php-mbstring
49     pip3 install --user behave nose
50
51     composer global require "squizlabs/php_codesniffer=*"
52     sudo ln -s ~/.config/composer/vendor/bin/phpcs /usr/bin/
53
54     composer global require "phpunit/phpunit=^7"
55     sudo ln -s ~/.config/composer/vendor/bin/phpunit /usr/bin/
56
57 #
58 # System Configuration
59 # ====================
60 #
61 # The following steps are meant to configure a fresh CentOS installation
62 # for use with Nominatim. You may skip some of the steps if you have your
63 # OS already configured.
64 #
65 # Creating Dedicated User Accounts
66 # --------------------------------
67 #
68 # Nominatim will run as a global service on your machine. It is therefore
69 # best to install it under its own separate user account. In the following
70 # we assume this user is called nominatim and the installation will be in
71 # /srv/nominatim. To create the user and directory run:
72 #
73 sudo mkdir -p /srv/nominatim       #DOCS:    sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
74 sudo chown vagrant /srv/nominatim  #DOCS:
75 #
76 # You may find a more suitable location if you wish.
77 #
78 # To be able to copy and paste instructions from this manual, export
79 # user name and home directory now like this:
80 #
81     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
82     export USERHOME=/srv/nominatim
83 #
84 # **Never, ever run the installation as a root user.** You have been warned.
85 #
86 # Make sure that system servers can read from the home directory:
87
88     chmod a+x $USERHOME
89
90 # Setting up PostgreSQL
91 # ---------------------
92 #
93 # CentOS does not automatically create a database cluster. Therefore, start
94 # with initializing the database, then enable the server to start at boot:
95
96
97     sudo /usr/pgsql-10/bin/postgresql-10-setup initdb
98     sudo systemctl enable postgresql-10
99
100 #
101 # Next tune the postgresql configuration, which is located in 
102 # `/var/lib/pgsql/data/postgresql.conf`. See section *Postgres Tuning* in
103 # [the installation page](../admin/Installation.md#postgresql-tuning)
104 # for the parameters to change.
105 #
106 # Now start the postgresql service after updating this config file.
107
108     sudo systemctl restart postgresql-10
109
110 #
111 # Finally, we need to add two postgres users: one for the user that does
112 # the import and another for the webserver which should access the database
113 # only for reading:
114 #
115
116     sudo -u postgres createuser -s $USERNAME
117     sudo -u postgres createuser apache
118
119 #
120 # Setting up the Apache Webserver
121 # -------------------------------
122 #
123 # You need to create an alias to the website directory in your apache
124 # configuration. Add a separate nominatim configuration to your webserver:
125
126 #DOCS:```sh
127 sudo tee /etc/httpd/conf.d/nominatim.conf << EOFAPACHECONF
128 <Directory "$USERHOME/build/website">
129   Options FollowSymLinks MultiViews
130   AddType text/html   .php
131   DirectoryIndex search.php
132   Require all granted
133 </Directory>
134
135 Alias /nominatim $USERHOME/build/website
136 EOFAPACHECONF
137 #DOCS:```
138
139 sudo sed -i 's:#.*::' /etc/httpd/conf.d/nominatim.conf #DOCS:
140
141 #
142 # Then reload apache
143 #
144
145     sudo systemctl enable httpd
146     sudo systemctl restart httpd
147
148
149 #
150 # Installing Nominatim
151 # ====================
152 #
153 # Building and Configuration
154 # --------------------------
155 #
156 # Get the source code from Github and change into the source directory
157 #
158 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
159     cd $USERHOME
160     git clone --recursive git://github.com/openstreetmap/Nominatim.git
161     cd Nominatim
162 else                               #DOCS:
163     cd $USERHOME/Nominatim         #DOCS:
164 fi                                 #DOCS:
165
166 # When installing the latest source from github, you also need to
167 # download the country grid:
168
169 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
170     wget --no-verbose -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
171 fi                                 #DOCS:
172
173 # The code must be built in a separate directory. Create this directory,
174 # then configure and build Nominatim in there:
175
176 #DOCS:    :::sh
177     cd $USERHOME
178     mkdir build
179     cd build
180     cmake $USERHOME/Nominatim
181     make
182
183 #
184 # Adding SELinux Security Settings
185 # --------------------------------
186 #
187 # It is a good idea to leave SELinux enabled and enforcing, particularly
188 # with a web server accessible from the Internet. At a minimum the
189 # following SELinux labeling should be done for Nominatim:
190
191     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/Nominatim/(website|lib|settings)(/.*)?"
192     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/build/(website|lib|settings)(/.*)?"
193     sudo semanage fcontext -a -t lib_t "$USERHOME/build/module/nominatim.so"
194     sudo restorecon -R -v $USERHOME/Nominatim
195     sudo restorecon -R -v $USERHOME/build
196
197
198 # You need to create a minimal configuration file that tells nominatim
199 # the name of your webserver user and the URL of the website:
200
201 #DOCS:```sh
202 tee settings/local.php << EOF
203 <?php
204  @define('CONST_Database_Web_User', 'apache');
205  @define('CONST_Website_BaseURL', '/nominatim/');
206 EOF
207 #DOCS:```
208
209
210 # Nominatim is now ready to use. Continue with
211 # [importing a database from OSM data](../admin/Import-and-Update.md).