1 # Deploying Nominatim using the PHP frontend
 
   3 The Nominatim API is implemented as a PHP application. The `website/` directory
 
   4 in the project directory contains the configured website. You can serve this
 
   5 in a production environment with any web server that is capable to run
 
   8 This section gives a quick overview on how to configure Apache and Nginx to
 
   9 serve Nominatim. It is not meant as a full system administration guide on how
 
  10 to run a web service. Please refer to the documentation of
 
  11 [Apache](https://httpd.apache.org/docs/current/) and
 
  12 [Nginx](https://nginx.org/en/docs/)
 
  13 for background information on configuring the services.
 
  16     Throughout this page, we assume your Nominatim project directory is
 
  17     located in `/srv/nominatim-project` and you have installed Nominatim
 
  18     using the default installation prefix `/usr/local`. If you have put it
 
  19     somewhere else, you need to adjust the commands and configuration
 
  22     We further assume that your web server runs as user `www-data`. Older
 
  23     versions of CentOS may still use the user name `apache`. You also need
 
  24     to adapt the instructions in this case.
 
  26 ## Making the website directory accessible
 
  28 You need to make sure that the `website` directory is accessible for the
 
  29 web server user. You can check that the permissions are correct by accessing
 
  30 on of the php files as the web server user:
 
  33 sudo -u www-data head -n 1 /srv/nominatim-project/website/search.php
 
  36 If this shows a permission error, then you need to adapt the permissions of
 
  37 each directory in the path so that it is executable for `www-data`.
 
  39 If you have SELinux enabled, further adjustments may be necessary to give the
 
  40 web server access. At a minimum the following SELinux labelling should be done
 
  44 sudo semanage fcontext -a -t httpd_sys_content_t "/usr/local/nominatim/lib/lib-php(/.*)?"
 
  45 sudo semanage fcontext -a -t httpd_sys_content_t "/srv/nominatim-project/website(/.*)?"
 
  46 sudo semanage fcontext -a -t lib_t "/srv/nominatim-project/module/nominatim.so"
 
  47 sudo restorecon -R -v /usr/local/lib/nominatim
 
  48 sudo restorecon -R -v /srv/nominatim-project
 
  51 ## Nominatim with Apache
 
  53 ### Installing the required packages
 
  55 With Apache you can use the PHP module to run Nominatim.
 
  57 Under Ubuntu/Debian install them with:
 
  60 sudo apt install apache2 libapache2-mod-php
 
  63 ### Configuring Apache
 
  65 Make sure your Apache configuration contains the required permissions for the
 
  66 directory and create an alias:
 
  69 <Directory "/srv/nominatim-project/website">
 
  70   Options FollowSymLinks MultiViews
 
  71   AddType text/html   .php
 
  72   DirectoryIndex search.php
 
  75 Alias /nominatim /srv/nominatim-project/website
 
  78 After making changes in the apache config you need to restart apache.
 
  79 The website should now be available on `http://localhost/nominatim`.
 
  81 ## Nominatim with Nginx
 
  83 ### Installing the required packages
 
  85 Nginx has no built-in PHP interpreter. You need to use php-fpm as a daemon for
 
  88 On Ubuntu/Debian install nginx and php-fpm with:
 
  91 sudo apt install nginx php-fpm
 
  94 ### Configure php-fpm and Nginx
 
  96 By default php-fpm listens on a network socket. If you want it to listen to a
 
  97 Unix socket instead, change the pool configuration
 
  98 (`/etc/php/<php version>/fpm/pool.d/www.conf`) as follows:
 
 101 ; Replace the tcp listener and add the unix socket
 
 102 listen = /var/run/php-fpm-nominatim.sock
 
 104 ; Ensure that the daemon runs as the correct user
 
 105 listen.owner = www-data
 
 106 listen.group = www-data
 
 110 Tell nginx that php files are special and to fastcgi_pass to the php-fpm
 
 111 unix socket by adding the location definition to the default configuration.
 
 114 root /srv/nominatim-project/website;
 
 117     try_files $uri $uri/ @php;
 
 121     fastcgi_param SCRIPT_FILENAME "$document_root$uri.php";
 
 122     fastcgi_param PATH_TRANSLATED "$document_root$uri.php";
 
 123     fastcgi_param QUERY_STRING    $args;
 
 124     fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
 
 125     fastcgi_index index.php;
 
 126     include fastcgi_params;
 
 129 location ~ [^/]\.php(/|$) {
 
 130     fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 
 131     if (!-f $document_root$fastcgi_script_name) {
 
 134     fastcgi_pass unix:/var/run/php-fpm-nominatim.sock;
 
 135     fastcgi_index search.php;
 
 136     include fastcgi.conf;
 
 140 Restart the nginx and php-fpm services and the website should now be available
 
 141 at `http://localhost/`.
 
 143 ## Nominatim with other webservers
 
 145 Users have created instructions for other webservers:
 
 147 * [Caddy](https://github.com/osm-search/Nominatim/discussions/2580)