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