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