Skip to content

Instantly share code, notes, and snippets.

@pvgenuchten
Last active May 22, 2026 12:39
Show Gist options
  • Select an option

  • Save pvgenuchten/0a3c9ce3f4b09ecdf963919afc859a0a to your computer and use it in GitHub Desktop.

Select an option

Save pvgenuchten/0a3c9ce3f4b09ecdf963919afc859a0a to your computer and use it in GitHub Desktop.
a simple setup of mapserver to test locally with ogcapi and index page

goal is to have a quick local setup for mapserver, to test some things in ogcapi and index page (relatively new features on mapserver).

create a mapfile countries.map

MAP
  NAME "countries"
  STATUS ON
  EXTENT -180 -90 180 90
  SIZE 800 400
  IMAGETYPE PNG
  WEB
    METADATA
      "ows_title"                   "Countries API"
      "ows_enable_request"          "*"
      "ows_srs"                     "EPSG:4326"
      "oga_onlineresource"          "http://localhost:8080/"
      "oga_enable_request"          "*"
      "oga_title"                   "Countries"
      "oga_description"             "Simple countries dataset"
    END
  END
  PROJECTION
    "init=epsg:4326"
  END

  LAYER
    NAME "countries"
    TYPE POLYGON
    STATUS ON

    CONNECTIONTYPE OGR
    CONNECTION "/data/countries.geojson"

    PROJECTION
      "init=epsg:4326"
    END

    CLASS
      STYLE
        COLOR 220 220 220
        OUTLINECOLOR 100 100 100
      END
    END

    METADATA
      "gml_include_items" "all"
      "oga_feature_collection" "true"
    END
  END
END

create a config file mapserver.conf

CONFIG

  ENV
    MS_ERRORFILE "stdout"
    # -----------------------------
    # OGC API HTML templates
    # -----------------------------
    OGCAPI_HTML_TEMPLATE_DIRECTORY "/usr/local/share/mapserver/ogcapi/templates/html-bootstrap/"
    # -----------------------------
    # MapServer classic HTML templates (GetMap, query, etc.)
    # -----------------------------
    MS_INDEX_TEMPLATE_DIRECTORY "/usr/local/share/mapserver/ogcapi/templates/html-index-bootstrap"
  END

  MAPS
    countries "/etc/mapserver/countries.map"
  END

END

Download geojson/ne_110m_admin_0_countries.geojson as countries.json and place it in a folder data

Then run the container

docker run --rm -p 8080:80 \
  -v $(pwd)/mapserver.conf:/etc/mapserver/mapserver.conf:ro \
  -v $(pwd)/countries.map:/etc/mapserver/countries.map:ro \
  -v $(pwd)/data:/data:ro \
  -e MAPSERVER_CONFIG_FILE=/etc/mapserver/mapserver.conf \
  camptocamp/mapserver:8.6

Open a browser and navigate to http://localhost:8080/countries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment