# Environement setup for Linux

Before install and launch Gisgraphy, you must setup java, postgres, and postgis. it is not, properly speaking, the installation of gisgraphy, and if you already have postgres, postgis and java installed, you can go directly to the gisgraphy installation guide

## Install and configure java / JVM

If you already have Java installed, you can skip this section

### Install Java

Open a shell and type :
sudo apt-get install sun-java6-bin sun-java6-fonts sun-java6-javadb sun-java6-jdk sun-java6-jre sun-java6-source ia32-sun-java6-bin
Valid screen (tab + OK) :
Accept the license (TAB to select 'yes' + OK) :
To see if Java is correctly installed, open a shell and type :
java -version
You should see :

    java version "1.6.0_06"
    Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)

We will now configure the Java.

### Configure Java

Open a shell and type :
sudo update-java-alternatives --set ia32-java-6-sun
You may have this message if you are on a 64 bits machine : Impossible de find alternative « /usr/lib/jvm/ia32-java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so ". thats not important. that's because there is no applet in 64 bits.
To see if java is well configured type "ls -l /etc/alternatives/java" you should see "/usr/lib/jvm/java-6-sun/jre/bin/java"
We now need to add a JAVA_HOME environement variable :

- add this line to .bashrc in your home directoy
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.06/
- execute "source ~/.bashrc" in a shell to take the changes into account.

Type "echo $JAVA_HOME" to check it is well set : /usr/lib/jvm/java-6-sun-1.6.0.06/
The JVM is now well installed

## Install postgresql and postgis

If you already have Postgresql AND Postgis installed, you can skip this section

### Install the debian / ubuntu package

Open a shell and type :
sudo apt-get install postgresql-8.3 postgresql-8.3-postgis
It is HIGHLY recommended to have postgis 1.3.1 or greater and postgresql-8.3 for good performances....
Those packages are availables from ubuntu hardy, it is recommended to update your ubuntu distribution if you have a lesser version

### Configure the postgres user / password

By default the postgres user can connect to postgres with the same password as the Unix one, but we'd like that postgres ask for a password and not use the UNIX one

- Change postgres (unix) user :
sudo passwd postgres
- Log to Unix with user 'postgres' :
su - postgres
and give the new password you've just type
- Check postgresql conf :
vim /etc/postgresql/8.3/main/pg_hba.conf
and edit it in order to have (at least) those 2 lines

    local  all     all                                        ident sameuser
    host   all     all    127.0.0.1         255.255.255.255   ident sameuser

- Define the postgres (postgresql) user's password
Connect to postgres to change the postgresql password :
psql -d template1 -c "alter user postgres with password 'YOURPASSWORD'"
now you've changed the password for your postgresql user, we have to tell postgresql to use this password
- Update postgres conf
Open a shell and Type :
vim /etc/postgresql/8.3/main/pg_hba.conf
and edit in order to have (at least) those two lines :

    local  all     all                                        password
    host   all     all    127.0.0.1         255.255.255.255   password

- Restart postgres
we must restart postresql to take our changes into account :
Close your postgres 's Linux session, type :
exit
Restart postgres :
sudo /etc/init.d/postgresql-8.3 restart

Tips : Install PGAdmin. It will be more user friendly than command line.
In order to know if Postgis is correctly install, open a PostgreSQL connection or PgAdmin and type :

- `select version ();` or `SHOW server_version;`. It will give you the PostgreSQL version
- `select postgis_full_version () ;` It will give you the Postgis version

## Define Linux settings

unix system define a maximum number of files that can be open. solr open a large number of files. to avoid message like "Too many open files" you must increase this limit. open a shell and type

    sudo ulimit -n6000

will set the maximum number of open files to 6000.
Sometimes this is not enough. and you have to edit the /etc/security/limits.conf file and add the two following lines :

    * hard nofile 20000
    * soft nofile 20000

then close and re-open your unix session to take changes into account.
type `ulimit -aH` in a shell to check if the value has been set

## And now...

Now that you environement is setup, you can go to the Gisgraphy installation guide for Linux