]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Centos-7.sh
19b7ff84802cedd9f4ea1588ec53ade24a8647af
[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 # Now you can install all packages needed for Nominatim:
21
22 #DOCS:    :::sh
23     sudo yum install -y postgresql-server postgresql-contrib postgresql-devel \
24                         postgis postgis-utils \
25                         wget git cmake make gcc gcc-c++ libtool policycoreutils-python \
26                         php-pgsql php php-intl libpqxx-devel \
27                         proj-epsg bzip2-devel proj-devel libxml2-devel boost-devel \
28                         expat-devel zlib-devel
29
30 # If you want to run the test suite, you need to install the following
31 # additional packages:
32
33 #DOCS:    :::sh
34     sudo yum install -y python34-pip python34-setuptools python34-devel \
35                         php-phpunit-PHPUnit
36     pip3 install --user behave nose pytidylib psycopg2
37
38     composer global require "squizlabs/php_codesniffer=*"
39     sudo ln -s ~/.config/composer/vendor/bin/phpcs /usr/bin/
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     sudo postgresql-setup initdb
81     sudo systemctl enable postgresql
82
83 #
84 # Next tune the postgresql configuration, which is located in 
85 # `/var/lib/pgsql/data/postgresql.conf`. See section *Postgres Tuning* in
86 # [the installation page](../admin/Installation.md#postgresql-tuning)
87 # for the parameters to change.
88 #
89 # Now start the postgresql service after updating this config file.
90
91     sudo systemctl restart postgresql
92
93 #
94 # Finally, we need to add two postgres users: one for the user that does
95 # the import and another for the webserver which should access the database
96 # only for reading:
97 #
98
99     sudo -u postgres createuser -s $USERNAME
100     sudo -u postgres createuser apache
101
102 #
103 # Setting up the Apache Webserver
104 # -------------------------------
105 #
106 # You need to create an alias to the website directory in your apache
107 # configuration. Add a separate nominatim configuration to your webserver:
108
109 #DOCS:```sh
110 sudo tee /etc/httpd/conf.d/nominatim.conf << EOFAPACHECONF
111 <Directory "$USERHOME/build/website">
112   Options FollowSymLinks MultiViews
113   AddType text/html   .php
114   DirectoryIndex search.php
115   Require all granted
116 </Directory>
117
118 Alias /nominatim $USERHOME/build/website
119 EOFAPACHECONF
120 #DOCS:```
121
122 sudo sed -i 's:#.*::' /etc/httpd/conf.d/nominatim.conf #DOCS:
123
124 #
125 # Then reload apache
126 #
127
128     sudo systemctl enable httpd
129     sudo systemctl restart httpd
130
131
132 #
133 # Installing Nominatim
134 # ====================
135 #
136 # Building and Configuration
137 # --------------------------
138 #
139 # Get the source code from Github and change into the source directory
140 #
141 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
142     cd $USERHOME
143     git clone --recursive git://github.com/openstreetmap/Nominatim.git
144     cd Nominatim
145 else                               #DOCS:
146     cd $USERHOME/Nominatim         #DOCS:
147 fi                                 #DOCS:
148
149 # When installing the latest source from github, you also need to
150 # download the country grid:
151
152 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
153     wget -O data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz
154 fi                                 #DOCS:
155
156 # The code must be built in a separate directory. Create this directory,
157 # then configure and build Nominatim in there:
158
159 #DOCS:    :::sh
160     cd $USERHOME
161     mkdir build
162     cd build
163     cmake $USERHOME/Nominatim
164     make
165
166 #
167 # Adding SELinux Security Settings
168 # --------------------------------
169 #
170 # It is a good idea to leave SELinux enabled and enforcing, particularly
171 # with a web server accessible from the Internet. At a minimum the
172 # following SELinux labeling should be done for Nominatim:
173
174     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/Nominatim/(website|lib|settings)(/.*)?"
175     sudo semanage fcontext -a -t httpd_sys_content_t "$USERHOME/build/(website|lib|settings)(/.*)?"
176     sudo semanage fcontext -a -t lib_t "$USERHOME/build/module/nominatim.so"
177     sudo restorecon -R -v $USERHOME/Nominatim
178     sudo restorecon -R -v $USERHOME/build
179
180
181 # You need to create a minimal configuration file that tells nominatim
182 # the name of your webserver user and the URL of the website:
183
184 #DOCS:```sh
185 tee settings/local.php << EOF
186 <?php
187  @define('CONST_Database_Web_User', 'apache');
188  @define('CONST_Website_BaseURL', '/nominatim/');
189 EOF
190 #DOCS:```
191
192
193 # Nominatim is now ready to use. Continue with
194 # [importing a database from OSM data](../admin/Import-and-Update.md).