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