Geoserver + PostGIS on OpenShift

I wanted to have my own Geoserver development environment for free (as in speech) when I found this great blog post by Steve Citron-Pousty:

Build your own Google Maps (and more) with Geoserver on OpenShift.

I am fairly familiar with Geoserver and wasn’t interested in the sample data provided on the GitHub page for this tutorial. In my setup I use the Geoserver 2.7.0 web archive which I downloaded from the Geoserver project page.

I signed up for a free account with OpenShift which gives us 3 free gears to use. These gears will hibernate after a day or so but it is possible to upgrade the account to bronze (no monthly charge) which means that the 3 free gears won’t hibernate. Upgrade to bronze requires you to submit your credit card details and is not yet available in all regions.

I run the setup from a Windows 8 machine with Powershell. Pre-requisites are Ruby, GIT, and RHC.

To create the application on Openshift use following command:

$ rhc app create geoserver -s tomcat7 postgresql-9

geoserver being the name of the new application and tomcat7 and postgresql-9 the cartridges which are used on the Openshift platform.

A local git clone will be created. From this clone remove the pom.xml since we are not interested in a Maven build.

From the git root open a secure shell into the application:

$ rhc ssh

In the application shell create a directory for the geoserver application data.

mkdir $OPENSHIFT_DATA_DIR/geoserver_data

From the application shell open a pSQL shell.

psql

In the pSQL shell enable the PostGIS extension for the default database.

CREATE EXTENSION postgis;

Exit the pSQL shell with CTRL+D and exit the application shell with ‘exit’.

Rename the Geoserver web archive to ROOT.war and move the file into the webapps directory of the GIT clone.

In .openshift\action_hooks create the file pre_start_jbossews-2.0 with the content line: ‘export CATALINA_OPTS=-DGEOSERVER_DATA_DIR=${OPENSHIFT_DATA_DIR}geoserver_data’

Geoserver would be useless if you cannot access the services from other client applications. In order to enable CORS for Tomcat edit the .openshift\config\web.xml and add following filter:

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Now add, commit and push these changes to OpenShift.

$ git add -A
$ git commit -am "prep work geoserver"
$ git push

The setup may take a few minutes since the Geoserver web archive is rather large (~60mb).

Once the application has fully started you can login to the admin console at http://geoserver-{your account}.rhcloud.com/web/

Change the admin password first, thereafter you can start to setup your workspaces, stores, styles, and layers.

I use QGIS to upload my data into the PostGIS database which we created. In order to access the database from my local machine I need to enable port forwarding like so.

$ rhc port-forward

2 thoughts on “Geoserver + PostGIS on OpenShift”

  1. Thanks a lot for the article. My question is regarding to extensions.
    How Geoserver extensions are installed in OpenShift?

    1. Not sure. I never tried to install an extension on my OpenShift setup and moved since then to use DigitalOcean exclusively.

Leave a Reply

Your email address will not be published. Required fields are marked *