How to Install Nominatim on Ubuntu Server Latest

Nominatim is an open-source tool that helps in searching and geocoding using open street maps. It is a powerful tool for geocoding and search applications. In this tutorial, we will learn how to install Nominatim using open street maps on Ubuntu server latest.

Prerequisites

Before starting the installation process, you will need the following:

Step 1: Install Required Dependencies

To install Nominatim, we need to install some required dependencies like Apache, PHP, and PostgreSQL.

Firstly, update and upgrade the system:

sudo apt update && sudo apt upgrade -y

After updating the system, install the required dependencies by running the following command:

sudo apt install build-essential cmake g++ libboost-dev libboost-system-dev \
libboost-filesystem-dev libexpat1-dev zlib1g-dev libxml2-dev \
libbz2-dev libpq-dev libproj-dev postgresql postgresql-contrib \
postgresql-server-dev-all apache2 php php-pgsql php-intl -y

Step 2: Create a PostgreSQL User and Database

To create a PostgreSQL user and database, follow the below command:

sudo su - postgres
createuser nominatim
createdb -E UTF8 -O nominatim nominatim
exit

Step 3: Download and Compile Nominatim

Download the latest version of the Nominatim code from the GitHub repository:

cd ~
sudo mkdir nominatim && cd nominatim
sudo git clone --recursive https://github.com/osm-search/Nominatim.git

Compile the Nominatim code using the following commands:

cd Nominatim
sudo mkdir build && cd build
sudo cmake ..
sudo make
sudo make install

During the compilation process, it may prompt you to download required files, and you can continue by pressing y.

Step 4: Set Up Nominatim

After installing the Nominatim code, you need to set up the necessary files and configurations.

  1. Download the required admin file:

    sudo wget "https://www.nominatim.org/data/country_grid.sql.gz"
    sudo gunzip country_grid.sql.gz
    
  2. Edit the local.php file:

    sudo nano /usr/local/src/Nominatim/settings/local.php
    

    And update the following configurations:

    @define('CONST_Postgresql_Version', '12'); // Update PostgreSQL version
    @define('CONST_Website_BaseURL', 'http://yourdomain.com/nominatim/'); // Update your domain or IP address
    @define('CONST_Database_DSN', 'pgsql:host=localhost;port=5432;dbname=nominatim'); // Do not change if you’re using PostgreSQL 12
    
    /**
     * Email address to send error reports to.
     * Do not set if you don't want to see errors
     * on the web page.
     * This address is also used as a sender address for
     * update mails.
     */
    @define('CONST_Contact_Email', 'nominatimuser@example.com'); // Update your email address
    

    Save and close the file by pressing CTRL+X, then Y, and then ENTER.

  3. Set up Apache Configuration:

    sudo nano /etc/apache2/sites-available/nominatim.conf
    

    Add the following content:

    <VirtualHost *:80>
            ServerName your-ip-address
            DocumentRoot /usr/local/src/Nominatim/build/nominatim/
    
            ErrorLog ${APACHE_LOG_DIR}/yourdomain_error.log
            CustomLog ${APACHE_LOG_DIR}/yourdomain_access.log combined
    
            <Directory "/usr/local/src/Nominatim/build/nominatim/">
                    Options FollowSymLinks MultiViews
                    AllowOverride None
                    Require all granted
            </Directory>
    </VirtualHost>
    

    Save and close the file.

  4. Enable the nominatim.conf file:

    sudo a2ensite nominatim.conf
    
  5. Restart the Apache service:

    sudo systemctl restart apache2
    
  6. Load the data:

    The last step is to load the data into the database. To load the data, you need to download the data file for your country from the OpenStreetMap website.

    cd /usr/local/src/Nominatim/build/utils
    sudo ./setup.php --osm-file /path/to/data.osm.pbf --all
    

Conclusion

In this tutorial, we have learned how to install Nominatim on Ubuntu Server Latest. Nominatim is now ready to be used for geocoding and search applications.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!