]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-18-nginx.sh
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / vagrant / Install-on-Ubuntu-18-nginx.sh
1 #!/bin/bash
2
3 #
4 # This is variation of Install-on-Ubuntu.sh showcasing how to use the
5 # nginx webserver instead of Apache2. We might eventually merge both
6 # files. Right now expect this file to become outdated/unmaintained
7 # over time.
8 #
9 # This file lacks many comments found in Install-on-Ubuntu.sh, you
10 # should check that file first to get a basic understanding.
11 #
12
13 # hacks for broken vagrant box
14 sudo rm -f /var/lib/dpkg/lock
15 sudo update-locale LANG=en_US.UTF-8
16 export APT_LISTCHANGES_FRONTEND=none
17 export DEBIAN_FRONTEND=noninteractive
18
19     sudo apt-get update -qq
20     sudo apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
21                             libboost-filesystem-dev libexpat1-dev zlib1g-dev\
22                             libbz2-dev libpq-dev libproj-dev \
23                             postgresql-server-dev-10 postgresql-10-postgis-2.4 \
24                             postgresql-contrib-10 \
25                             nginx php-fpm php php-pgsql \
26                             php-intl python3-setuptools python3-dev python3-pip \
27                             python3-psycopg2 python3-tidylib git
28
29     export USERNAME=vagrant
30     export USERHOME=/home/vagrant
31
32     chmod a+x $USERHOME
33
34 # Setting up PostgreSQL
35 # ---------------------
36 #
37 # Tune the postgresql configuration, see same section in Install-on-Ubuntu.sh
38
39     sudo systemctl restart postgresql
40
41     sudo -u postgres createuser -s $USERNAME
42     sudo -u postgres createuser www-data
43
44 #
45 # Setting up the Nginx Webserver
46 # -------------------------------
47 #
48 # You need to configure php-fpm to listen on a Unix socket. Then create Nginx
49 # configuration to forward localhost:80 requests to that socket.
50 #
51
52
53 sudo tee /etc/php/7.2/fpm/pool.d/www.conf << EOF_PHP_FPM_CONF
54 [www]
55 ; Comment out the tcp listener and add the unix socket
56 ;listen = 127.0.0.1:9000
57 listen = /var/run/php7.2-fpm.sock
58
59 ; Ensure that the daemon runs as the correct user
60 listen.owner = www-data
61 listen.group = www-data
62 listen.mode = 0666
63
64 ; Unix user of FPM processes
65 user = www-data
66 group = www-data
67
68 ; Choose process manager type (static, dynamic, ondemand)
69 pm = ondemand
70 pm.max_children = 5
71 EOF_PHP_FPM_CONF
72
73
74
75
76 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
77 server {
78     listen 80 default_server;
79     listen [::]:80 default_server;
80
81     root $USERHOME/build/website;
82     index search.php index.html;
83     location / {
84         try_files \$uri \$uri/ @php;
85     }
86
87     location @php {
88         fastcgi_param SCRIPT_FILENAME "\$document_root\$uri.php";
89         fastcgi_param PATH_TRANSLATED "\$document_root\$uri.php";
90         fastcgi_param QUERY_STRING    \$args;
91         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
92         fastcgi_index index.php;
93         include fastcgi_params;
94     }
95
96     location ~ [^/]\.php(/|$) {
97         fastcgi_split_path_info ^(.+?\.php)(/.*)$;
98         if (!-f \$document_root\$fastcgi_script_name) {
99             return 404;
100         }
101         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
102         fastcgi_index search.php;
103         include fastcgi.conf;
104     }
105 }
106 EOF_NGINX_CONF
107
108
109 sudo sed -i 's:#.*::' /etc/nginx/sites-available/default
110
111
112 #
113 # Enable the configuration and restart Nginx
114 #
115
116     sudo systemctl stop apache2 # just in case it's installed as well
117     sudo systemctl restart php7.2-fpm nginx
118
119 # From here continue in the 'Installing Nominatim' section in
120 # Install-on-Ubuntu.sh
121