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