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