Installing postgis and mapserver in Debian Lenny in 30-something steps...

Don't know this is the preferred way, but it's working at this (march 2008) moment (for tips and errors: please let me know: richard@duif.net (Richard Duivenvoorde)

  • install debian lenny (current testing)
  • install synaptic via apt-get install synaptic
  • either use synaptic to install the following packages OR via command-line:
  • apt-get install postgis postgresql-8.2-postgis postgresql-doc cgi-mapserver mapserver-bin mapserver-doc apache2 (lenny is using 8.3 currently, but I'm not sure if the postgis stuff is working in that one...)
  • if you try to connect from another pc (eg using pgAdminIII) you get a 'server doesn't listen' error...
  • in /etc/postgresql/8.2/main/postgreql.conf at 'CONNECTIONS AND AUTHENTICATION' uncomment the line 'listen_addresses ...' and change to: listen_addresses = '*'
  • restart postgresql: /etc/init.d/postgresql-8.2 restart
  • now if you try to connect from another pc (using pgAdminIII) you get a prompt: "pleaseenter password for user postgres"...
  • and probably the error "access to database denied FATAL: no pg_hba.conf entry for host "192.168.1.67", user "postgres", database "postgres"
  • so we have to let te server know that we allow other pc's to connect to it: at the end of the file /etc/postgresql/8.2/main/pg_hba.conf add a line
    host all all 192.168.1.0/24 md5 # if you're network is in this range....
  • now read documentation of postgresql-postgis package (!) /usr/share/doc/postgresql-8.2-postgis/README.Debian.gz
  • you still can't connect from another pc because user postgres isn't 'normal user', to be able to create a password protected superuser for yourself, do su - postgres (log in as user postgres) and then create a new user for yourself: createuser -P -s -e richard
  • NOW you should be able to connect via pgAdminIII to the database using you're own username/password
  • being user 'postgres' (do: su - postgres), create a new database: createdb mygisdb --o richard
  • lines below almost verbatim from readme:
  • 'spatial enable' it (that is: add spatial functions to it) (as user postgres): by doing all steps from the readme:
  • 'enable plpgsql'(as user postgres): createlang plpgsql -d mygisdb
  • 'load functions(as user postgres, these scripts come from the postgresql-8.2-postgis package): psql mygisdb -f /usr/share/postgresql-8.2-postgis/lwpostgis.sql
  • 'load ref and proj tables (as user postgres): psql mygisdb -f /usr/share/postgresql-8.2-postgis/spatial_ref_sys.sql
  • log in in db: psql mygisdb (as user postgres)
  • grant priviliges on geotables: grant all on geometry_columns to richard
  • grant priviliges on proj tables: grant all on spatial_ref_sys to richard
  • now you should see your spatial enabled database in pgAdminIII (look for familiar function as box2d in the functions list :-) )
  • still not satisfied? you want to see a MAP ?
  • download some world data: wget http://aprsworld.net/gisdata/world/world.zip
  • unzip the files: unzip world.zip
  • use shp2pgsql (from postgis package) to convert this shapefile to a postgis dump: shp2pgsql world.shp world mygisdb > world.sql
  • you have a world.sql file now with all worlddata. Now let's load it into postgresql: (either as postgres, or you're own user): psql -d mygisdb < world.sql
  • and now you want to SEE a map, we are going to use qgis for that (of which there is only an 'old' version in the default debian repository...)
  • add deb http://debian.gfoss.it/ lenny main to you're repository list at /etc/apt/sources.list
  • via synaptic or: apt-get update and then apt-get install qgis install qgis
  • make a postgresql connection, and voila:

  • and now with mapserver...
  • mapserv is installed in /usr/lib/cgi-bin/mapserv
  • download this example mapfile and copy it next to mapserv
  • change username and password in it
  • in a browser: to view the capabilities: http://dame/cgi-bin/mapserv?map=world.map&request=getcapabilities&service=wms
  • or a map: http://yourmachine/cgi-bin/mapserv?map=world.map&mode=browse&layers=all&mode=map
  • if you see something like: image handling failed... Operation on two geometries with different SRID's, it's because the world import failed to set a srid (projection) for the data
  • just insert it in the geometry_columns table and update the geometries itself (fire query in pgAdminIII):
  • update geometry_columns set srid = 4326 where f_table_name = 'world'
  • select UpdateGeometrySRID('world', 'the_geom', 4326)
  • and again: http://yourmachine/cgi-bin/mapserv?map=world.map&mode=browse&layers=all&mode=map

    happy using linux/mapserver/postgis, sent me an email if it's usefull, I can make an ubuntu version if usefull also ...