]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/ubuntu-trusty-php7-provision.sh
fix for PHP7, added test setup
[nominatim.git] / vagrant / ubuntu-trusty-php7-provision.sh
1 #!/bin/bash
2
3 # This script sets up a Nominatim installation on a Ubuntu box.
4 #
5 # For more detailed installation instructions see also
6 # http://wiki.openstreetmap.org/wiki/Nominatim/Installation
7
8 ## Part 1: System preparation
9
10 ## During 'vagrant provision' this script runs as root and the current
11 ## directory is '/root'
12 USERNAME=vagrant
13
14 ### 
15 ### maybe create ubuntu user
16 ### 
17
18 # if [[ ! `id -u $USERNAME` ]]; then
19 #   useradd $USERNAME --create-home --shell /bin/bash
20 #   
21 #   # give sudo power
22 #   echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-$USERNAME-user
23 #   chmod 0440 /etc/sudoers.d/99-$USERNAME-user
24 #   service sudo restart
25 #   
26 #   # add basic .profile
27 #   cp -r .ssh .profile .bashrc /home/$USERNAME/
28 #   chown -R $USERNAME /home/$USERNAME/.*
29 #   chgrp -R $USERNAME /home/$USERNAME/.*
30 #   
31 #   # now ideally login as $USERNAME and continue
32 #   su $USERNAME -l
33 # fi
34
35
36 sudo apt-get update -qq
37 sudo apt-get upgrade -y
38 sudo apt-get install -y build-essential libgeos-dev libpq-dev libbz2-dev \
39                         libtool automake libproj-dev libboost-dev  libboost-system-dev \
40                         libboost-filesystem-dev libboost-thread-dev libexpat-dev
41 sudo apt-get autoremove -y
42
43 # get arrow-keys working in terminal (e.g. editing in vi)
44 echo 'stty sane' >> ~/.bash_profile
45 echo 'export TERM=linux' >> ~/.bash_profile
46 source ~/.bash_profile
47
48
49 ###
50 ### PostgreSQL 9.3 + PostGIS 2.1
51 ###
52
53 sudo apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib-9.3 postgresql-server-dev-9.3 
54 # already included: proj-bin libgeos-dev
55
56 # make sure OS-authenticated users (e.g. $USERNAME) can access
57 sudo sed -i "s/ident/trust/" /etc/postgresql/9.3/main/pg_hba.conf
58 sudo sed -i "s/md5/trust/"   /etc/postgresql/9.3/main/pg_hba.conf
59 sudo sed -i "s/peer/trust/"  /etc/postgresql/9.3/main/pg_hba.conf
60 sudo /etc/init.d/postgresql restart
61
62 # creates the role
63 sudo -u postgres createuser -s $USERNAME
64
65
66
67 ###
68 ### PHP for frontend
69 ###
70 sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
71 sudo apt-get update -qq
72 sudo apt-get install -y apache2
73 sudo apt-get install -y php7.0 php7.0-pgsql php7.0-fpm libapache2-mod-php7.0 php-pear php-db
74
75
76 # get rid of some warning
77 # where is the ini file? 'php --ini'
78 echo "date.timezone = 'Etc/UTC'" | sudo tee /etc/php/7.0/cli/conf.d/99-timezone.ini > /dev/null
79
80
81
82 ###
83 ### Nominatim
84 ###
85 sudo apt-get install -y libgeos-c1 libgeos++-dev libxml2-dev
86
87 ## Part 2: Nominatim installaion
88
89 # now ideally login as $USERNAME and continue
90 cd /home/$USERNAME
91
92 # If the Nominatim source is not being shared with the host, check out source.
93 if [ ! -d "Nominatim" ]; then
94   sudo apt-get install -y git
95   sudo -u $USERNAME git clone --recursive https://github.com/twain47/Nominatim.git
96 fi
97
98 cd Nominatim
99
100 sudo -u $USERNAME ./autogen.sh
101 sudo -u $USERNAME ./configure
102 sudo -u $USERNAME make
103 chmod +x ./
104 chmod +x ./module
105
106
107 LOCALSETTINGS_FILE='settings/local.php'
108 if [[ -e "$LOCALSETTINGS_FILE" ]]; then
109   echo "$LOCALSETTINGS_FILE already exist, writing to settings/local-vagrant.php instead."
110   LOCALSETTINGS_FILE='settings/local-vagrant.php'
111 fi
112
113 # IP=`curl -s http://bot.whatismyipaddress.com`
114 IP=localhost
115 echo "<?php
116    // General settings
117    @define('CONST_Database_DSN', 'pgsql://@/nominatim');
118    // Paths
119    @define('CONST_Postgresql_Version', '9.3');
120    @define('CONST_Postgis_Version', '2.1');
121    // Website settings
122    @define('CONST_Website_BaseURL', 'http://$IP:8089/nominatim/');
123 " > $LOCALSETTINGS_FILE
124
125
126
127
128
129
130
131 ###
132 ### Setup Apache/website
133 ###
134
135 sudo -u postgres createuser -SDR www-data
136
137 echo '
138 Listen 8089
139 <VirtualHost *:8089>
140     # DirectoryIndex index.html
141     # ErrorDocument 403 /index.html
142
143     DocumentRoot "/var/www/"
144  
145     <Directory "/var/www/nominatim/">
146       Options FollowSymLinks MultiViews
147       AddType text/html   .php     
148     </Directory>
149 </VirtualHost>
150 ' | sudo tee /etc/apache2/sites-enabled/nominatim.conf > /dev/null
151
152
153 service apache2 graceful
154
155
156 mkdir -m 755 /var/www/nominatim
157 chown $USERNAME /var/www/nominatim
158 sudo -u $USERNAME ./utils/setup.php --create-website /var/www/nominatim
159
160
161 # if you get 'permission denied for relation word', then try
162 # GRANT usage ON SCHEMA public TO "www-data";
163 # GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
164
165 ##
166 ## Test suite (Python)
167 ## https://github.com/twain47/Nominatim/tree/master/tests
168 ##
169 apt-get install -y python-dev python-pip python-Levenshtein python-shapely \
170                         python-psycopg2 tidy python-nose python-tidylib
171 pip install certifi # deals with "SNI extension to TLS is not available" warning
172 pip install lettuce==0.2.18 six==1.7 haversine
173 pip install --upgrade pip setuptools
174
175 ## Test suite (PHP)
176 ## https://github.com/twain47/Nominatim/tree/master/tests-php
177 wget --quiet https://phar.phpunit.de/phpunit.phar
178 chmod +x phpunit.phar
179 mv phpunit.phar /usr/local/bin/phpunit
180