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