Gisgraphy is a free opensource geocoding and webservices solution. It is a greate alternative to google’s geocoding API, which has lots of limitation on usage. Gisgraphy can provide the best relevance of geocoding, since it combines both geonames and openstreetmap dataset. In fact besides geocoding, Gisgraphy can be used for Reverse geocoding / street search, Street search, Find nearby, Fulltext search, Address parser. I’d recommend you go to their demo site and try it!

Here, I’ll show you how to install Gisgraphy 3.0 on your local machine with Ubuntu 12.04 step by step. I’ll use: Java JDK 7, PostgreSQL9.1 and Postgis 1.5 . ( Notice that Gisgraphy 3.0 does NOT support Postgis 2.0 ). The official site did provide a installation guide, but it is sort of out of data.

1. Install Java SDK

1.1 Install oracle-jdk7

Run the following commands inside of terminal to install jdk7:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-jdk7-installer

You can check if you successfully installed java by running:

java -version # should get java version "1.7.0_21" or something like that
javac -version # should get javac 1.7.0_21 or something like that

1.2 Set up Java environment

Open .bashrc file using vim or any other text editor:

sudo vim .bashrc

Add the following line at the end of file:

export JAVA_HOME=/usr/lib/jvm/java-7-oracle

Reload the settings by running:

source ~/.bashrc

Now you can check to see if the setting is effect by running

echo $JAVA_HOME # should return /usr/lib/jvm/java-7-oracle

2. Install PostgreSQL9.1 and Postgis 1.5

2.1 Install postgreSQL and postgis

Run the following command to install postgresql:

sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install libpq-dev
sudo apt-get install postgresql
sudo apt-get install postgresql-9.1-postgis

Check if postgresql is successfully installed:

psql -V

2.2 Create password for user: postgres

Enter postgres console with username ‘postgres’:

sudo -u postgres psql

Then, inside of postgres, run the following command to change password of ‘postgres’:

ALTER USER postgres PASSWORD 'yourpassword';
\q # quite postgres console

2.3 Create database, language and postgis function

All the following command will use the user ‘postgres’ with the password you just created.

# create the database
psql -U postgres -h 127.0.0.1 -c "CREATE DATABASE gisgraphy ENCODING = 'UTF8';"

#create language
createlang -U postgres -h 127.0.0.1 plpgsql gisgraphy

#create postgis function
psql -U postgres -h 127.0.0.1 -d gisgraphy -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql

psql -U postgres -h 127.0.0.1 -d gisgraphy -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql

After all the settings are done, restart the server by running:

sudo /etc/init.d/postgresql restart

3. Linux file limit settings

To avoid message like “Too many open files” when solr opens a large number of files, you must increase maximum number of files limit. Open terminal, and edit limits.conf file using vim:

sudo vim /etc/security/limits.conf

Add the following 2 lines to the file, notice do not miss the * mark:

* hard nofile 20000
* soft nofile 20000

That’s it, now everything is set up. And the next, we are going to install Gisgraphy server.

4. Insatll Gisgraphy

4.1 Download Gisgraphy

Download Gisgraphy from here.

Open your terminal, go to your directory where the file is downloaded, and unzip it:

unzip gisgraphy-3.0-beta2.zip

mv gisgraphy-3.0-beta2 gisgraphy

4.2 Initialize tables

After that, we need to create tables:

cd gisgraphy/

psql -Upostgres -d gisgraphy -h 127.0.0.1 -f ./sql/create_tables.sql

Then, add default user:

psql -Upostgres -d gisgraphy -h 127.0.0.1 -f ./sql/insert_users.sql

The above command will give two default user one is admin with password admin, the other one is user.

4.3 Settings

In order to make the server run, we need to fill the password of postgres in jdbc.properties file. Inside of gisgraphy directory:

vim webapps/ROOT/WEB-INF/classes/jdbc.properties

Open the jdbc.properties file, and fill the jdbc.password field with your password. Notice that do not leave any space after ‘=’

jdbc.username=postgres
jdbc.password=yourpassword

Then it’s pretty much done. Last thing is we can set up environment inside of env.properties file, which is also under webapps/ROOT/WEB-INF/classes/ directory.

There are 3 parameters that I think is worth to take a look at it. These are:

 importer.geonamesfilesToDownload=US.zip
 importer.openstreetmapfilesToDownload=US.tar.bz2
 googleMapAPIKey=yourkey

For me, I’m only interested about data in USA, so I set geonamesfilesToDownload and openstreetmapfilesToDownload to only download data for US. This will save us a lot of space. What’s more, the googleMapAPIKey can be used to show map in the demo server. You can get it from google’s api console.

All the other settings can be reference from the document.

4.4 Run the server

Ok, now it’s time to run the server. Change the file mode to executable, and then run it.

chmod +x launch.sh
./launch.sh

Now, you should be able to visit http://localhost:8080/mainMenu.html page.  Next thing is go through the wizard in the main page to download the dataset. Yeah!

13 Thoughts on “Install Gisgraphy on Ubuntu 12.04 from Scratch

  1. Hello Steven I’m using ubuntu server 12.04.5 when trying to run the first command on your tutorial sudo add-apt-repository ppa:webupd8team/java I got the following error and can’t proceed further.

    add-apt-repository: command not found

    Any ideas how to solve this issue?

    • Steven Yue on October 16, 2014 at 9:14 am said:

      Hi, Joe.

      Try to run the command below first:

      sudo apt-get install python-software-properties

      • Hello Steven

        I was able to get through however I’m now stuck at this part

        sudo apt-get install postgresql-9.1-postgis
        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        E: Unable to locate package postgresql-9.1-postgis
        E: Couldn’t find any package by regex ‘postgresql-9.1-postgis’

        Seems postgresql 9.1 postgis is not available any more. Any sugestions?

        • Steven Yue on October 16, 2014 at 9:48 am said:

          I just followed the step. And I didn’t see any problem. Maybe `sudo apt-get update` and do it again?

          • Im using Ubuntu Server 12.04.5. Could that be an issue?

            • Steven Yue on October 16, 2014 at 10:57 am said:

              Have you successfully added this PPA?

              sudo add-apt-repository ppa:pitti/postgresql

              • Hello Steven . Yes I’m able to install the repository.

                You are about to add the following PPA to your system:
                ATTENTION: The functionality of this has been moved to http://apt.postgresql.org, this PPA is deprecated. apt.postgresql.org has a lot more packages, and also better QA. This PPA will still be kept for Ubuntu 10.04′s life time, but will NOT receive ANY UPDATES any more.
                More info: https://launchpad.net/~pitti/+archive/ubuntu/postgresql
                Press [ENTER] to continue or ctrl-c to cancel adding it

                gpg: keyring `/tmp/tmp2TCYaD/secring.gpg’ created
                gpg: keyring `/tmp/tmp2TCYaD/pubring.gpg’ created
                gpg: requesting key 8683D8A2 from hkp server keyserver.ubuntu.com
                gpg: /tmp/tmp2TCYaD/trustdb.gpg: trustdb created
                gpg: key 8683D8A2: public key “Launchpad PPA for Martin Pitt” imported
                gpg: Total number processed: 1
                gpg: imported: 1 (RSA: 1)
                OK
                root@cl-t147-152cl:/home/sshadmin#

                I where also able to install the files below:

                sudo apt-get install libpq-dev
                sudo apt-get install postgresql

                The problem is when running the following command sudo add-apt-repository ppa:pitti/postgresql

                Reading package lists… Done
                Building dependency tree
                Reading state information… Done
                E: Unable to locate package postgresql-9.1-postgis
                E: Couldn’t find any package by regex ‘postgresql-9.1-postgis’

                  • Hello Steven

                    I added the repository as state on the link you provide. Seems it find some parts however it don’t let me go further. Apparently some files are missing. Here’s the output.

                    sudo apt-get install postgresql-9.1-postgis

                    Reading package lists… Done
                    Building dependency tree
                    Reading state information… Done
                    Note, selecting ‘postgresql-9.1-postgis-2.1-scripts’ for regex ‘postgresql-9.1-postgis’
                    Note, selecting ‘postgresql-9.1-postgis-scripts’ for regex ‘postgresql-9.1-postgis’
                    Note, selecting ‘postgresql-9.1-postgis-2.0′ for regex ‘postgresql-9.1-postgis’
                    Note, selecting ‘postgresql-9.1-postgis-2.1′ for regex ‘postgresql-9.1-postgis’
                    Note, selecting ‘postgresql-9.1-postgis-2.0-scripts’ for regex ‘postgresql-9.1-postgis’
                    Some packages could not be installed. This may mean that you have
                    requested an impossible situation or if you are using the unstable
                    distribution that some required packages have not yet been created
                    or been moved out of Incoming.
                    The following information may help resolve the situation:

                    The following packages have unmet dependencies:
                    postgresql-9.1-postgis-2.0 : Depends: libgdal1-1.7.0 but it is not installable
                    Depends: liblwgeom-2.0.3 (>= 2.0.2) but it is not going to be insta lled
                    Depends: libproj0 but it is not installable
                    Recommends: postgis but it is not going to be installed
                    postgresql-9.1-postgis-2.1 : Depends: libgdal1 (>= 1.9.0) but it is not going to be installed
                    Depends: liblwgeom-2.1.4 (>= 2.1.2) but it is not going to be insta lled
                    Depends: libproj0 but it is not installable
                    Recommends: postgis but it is not going to be installed
                    Recommends: postgresql-contrib-9.1 but it is not going to be instal led
                    E: Unable to correct problems, you have held broken packages.

    • Did you try

      sudo apt-get install postgresql-9.1-postgis-1.5

  2. Do you know the minimal hardware requeriments for the instalation (data of my country -Argentina- is quite small) ? Thanks!

    • Hi, I think it does not require that much CPU or memory. But it needs lots of disk space. It provides a very nice GUI where you can select the data of different country. I don’t know how large is the data for Argentina

Leave a Reply

Post Navigation