MapServer之安装和基本使用

MapServer之安装和基本使用

http://mapserver.org/

概述

MapServer 是一个发布空间数据和网络交互式地图制图应用的开源平台。最早在1990年代中期于 University of Minnesota 开发, MapServer 基于 MIT-style license 发布, 可以运行在主流的操作系统上 (Windows, Linux, Mac OS X). MapServer不是一个全功能的GIS系统,其目标不在于此.

MapServer当前最新版为 7.0.4,可前往官方网站下载页面下载源码或文档. 针对Windows系统目前有4个二进制版本:MS4WOSGeo4WFWToolsGisinternals

MS4W安装使用

建议使用二进制安装包形式

百度文库-MapServer的安装和使用

官方文档、或下载的安装包中的README_INSTALL.html

ms4w基本包里面包括以下内容:

  • Apache version 2.4.20
  • PHP version 5.4.45
  • MapServer 7.0.1 CGI and MapScript (PHP)
  • GDAL 2.1.0
  • MapCache 1.4.1
  • mapserver utilities
  • gdal/ogr utilities
  • proj.4 utilities
  • shp2tile utility
  • shapelib utilities
  • shpdiff utility
  • avce00 utilities
  • spatialite utilities
  • unixutils
  • OWTChart 1.2.0
  • H264 Streaming Module for Apache

从旧版本升级

  1. 打开一个DOS窗口(不要只是双击),切换到ms4w所在目录,执行apache-uninstall.bat,停止和移除之前的 Apache 服务。
The "Apache MS4W Web Server" service is stopping.
The "Apache MS4W Web Server" service has stopped.
Removing the "Apache MS4W Web Server" service
The "Apache MS4W Web Server" service has been removed
successfully.
  1. 备份你的旧的ms4w文件夹(或直接删除)

  2. 将下载的压缩包解压到相应的目录,如C:/ms4w

  3. 在DOS中执行apache-install.bat,安装 MS4W Apache Web Server。此操作将Apache服务安装为Windows服务,这样可以设置Apache随机器一起启动。如下出现下述信息,说明安装成功

    Installing the Apache MS4W Web Server service
    The Apache MS4W Web Server service is successfully installed.
    Testing httpd.conf....
    Errors reported here must be corrected before the service
    can be started.
    The Apache MS4W Web Server service is starting.
    The Apache MS4W Web Server service was started successfully.
  4. 浏览器访问http://localhost/http://127.0.0.1/ 测试是否启动

  5. 可能的错误:不能绑定到 80 端口

(OS 10013)以一种访问权限不允许的方式做了一个访问套接字的尝试。 : AH00072: make_sock: could not bind to address 0.0.0.0:80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
Apache MS4W Web Server 服务正在启动 .
Apache MS4W Web Server 服务无法启动。
发生服务特定错误: 1.
请键入 NET HELPMSG 3547 以获得更多的帮助。

这是因为系统的80 端口被占用了netstat -aon | findstr 80查看端口占用,tasklist |findstr 4查看进程)。通过以下方法可以解除占用^1:

  • 打开注册表,在cmd下输入:regedit
  • 找到:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP
  • 在右边找到Start这一项,将其改为0。
  • 重启系统,System进程不会占用80端口。

或者,修改Apache的默认端口80为8008(或其他未被使用的端口):

  • 打开ms4w\Apache\conf\httpd.conf文件,找到58行Listen 80,修改为Listen 8008

再次执行apache-install.bat(必要时需要先apache-uninstall.bat、以管理员身份启动DOS命令行),将会看到服务启动成功的信息。

打开浏览器访问http://localhost:8008/ (如果未修改Apache默认端口,则地址为http://localhost)会看到 MS4W - MapServer 4 Windows - version 3.1.4

若 ms4w 不是安装在磁盘的根目录,则需要进行配置。同时需要避免安装到包含空格的目录

/ms4w/Apache/conf/httpd.conf/ms4w/Apache/cgi-bin/php.ini/ms4w/Apache/cgi-bin/php.ini/ms4w/setenv.bat 文件中找到 /ms4w/替换为你的安装目录(如 “/Temp/ms4w/”)

应用组件

如果安装时(exe安装)选择了Mapbender 、Openlayers等组件,则在页面的Applications下面会有Mapbender 、OpenLayers 等组件的相关链接。

如果没有选择安装组件,可以访问组件页面 http://www.ms4w.com/release/apps/ 获取独立的组件包,下载后解压(解压到当前文件夹)到MS4W的根目录 (如, C:/,不是C:/ms4w目录下). 解压之后,

  • 相应应用的目录(如 ms-ogc-workshop)会出现在/ms4w/apps/目录下
  • 一个新的httpd_*.conf文件会添加到/ms4w/httpd.d/ 目录下. 如/ms4w/httpd.d/httpd_ms_ogc_workshop.conf

(/httpd.d/目录包含了Apache 的配置文件。这些配置文件决定了你计算机/服务器上哪些文件是可以通过web访问的。 每一个安装到Apache的web应用都会有一个新的配置文件.)

  • 重启Apache服务(apache-restart.bat),然后就可以在Applications发现其链接了。

访问http://127.0.0.1:8008/cgi-bin/mapserv.exe 会出现 No query information to decode. QUERY_STRING is set, but empty.

全新安装

如果是zip包形式安装,从上述第三步开始操作。若是使用二进制文件exe安装,双击exe文件,并选择需要的组件和安装目录即可安装,不需要手动执行apache-install.bat,同时ms4w会在开始菜单和桌面生成快捷方式(如果选择生成的话)

MapScript配置

完整内容参考 https://ms4w.com/README_INSTALL.html#mapscript-configuration

MS4W >= 1.5.0 包括了内置的对C#、Java和Python的支持。它们需要进行一些配置才能使用。

Python

首先需要安装Python,目前只支持 3.5.x (2018最新版本) (3.1.4 支持的是 2.7)

v3.2.7 中,支持的python 依然是2.7

安装 Python Mapscript 支持文件
  • 只能与 ms4w 一起使用
    • /ms4w/Apache/cgi-bin/mapscript/python/mapscript*win32.zip 解压到一个安全的目录(safe location)
    • 在解压后的目录中切换到 /Python-2.7.11/Lib/site-packages,在目录中会发现4个文件:
      • _mapscript.pyd
      • mapscript.py
      • mapscript.pyc
      • mapscript-<version>-py2.7.egg-info
    • 将4个文件拷贝到 /ms4w/Apache/cgi-bin 目录
    • 将所需运行的 python cgi scripts 放到 ms4w 的 /ms4w/Apache/cgi-bin 目录, 并且在每一个脚本的顶部加上一行 “shebang” 行. 具体信息往下看 配置Apache运行Python脚本 部分的内容。
  • 系统级访问
    • 解压/ms4w/Apache/cgi-bin/mapscript/python/mapscript*win32.zip
    • /Python-2.7.11/Lib/site-packages 目录,发现三个文件:
      • _mapscript.pyd
      • mapscript.py
      • mapscript.pyc
    • 将上述文件拷贝到你安装Python 2.7.x 的目录下的site-packages目录,如C:/Python27/Lib/site-packages
    • 添加<drive_letter>:/ms4w/Apache/cgi-bin 到系统的 PYTHONPATH 环境变量.

配置Apache运行Python脚本

通过shebang 行

当你的机器上安装有多个Python时,推荐此方法。

/ms4w/apache/cgi-bin中的每个 python cgi 脚本顶部添加 “shebang line” ,必须是首行,且必须是#!后跟你系统中的Python可执行文件路径. 如:

#!c:/python27/python.exe -u

The -u option shown above causes the script to use unbuffered output, which is generally what you need in web-serving contexts.

通过 Apache directives(指令)

#####测试

  • 将文件/ms4w/gdalbindings/python/test-cgi-mapscript.py 移到 /ms4w/Apache/cgi-bin/
  • 用文本编辑器打开,添加(修改)shebang 行,如#!C:\Python27\ArcGIS10.1\python.exe -u
  • 打开 http://127.0.0.1:8008/cgi-bin/test-cgi-mapscript.py (确保Apache已启动)

FastCGI

为使用 FastCGI 你必须进行如下操作:

  1. 在文本编辑器中打开 /ms4w/Apache/conf/httpd.conf

  2. 取消#178的注释, 如:

    LoadModule fcgid_module modules/mod_fcgid.so
  3. 文件底部会看到 “<IfModule fcgid_module>” 部分. 若想使用 FastCGI 指令, (listed on the mod_fcgid page) 你可以取消这部分内容的注释并添加自己的指令 directives, 如:

    <IfModule fcgid_module>
    FcgidMinProcessesPerClass 0
    FcgidIdleScanInterval 1
    FcgidProcessLifeTime 10
    </IfModule>
  4. 如需要使用FastCGI连接 Oracle 数据库, 必须添加 Oracle Bin 目录 (文件 ‘oci.dll’ 所在目录) 到上面的 PATH 变量, 如:

    <IfModule fcgid_module>
    ...
    FcgidInitialEnv PATH "c:/oracle/product/10.2.0/client/BIN"
    ...
    </IfModule>
  5. 保存并重启Apache (执行/ms4w/apache-restart.bat)

  6. 将 CGI 应用指向/fcgi-bin/mapserv.exe而不是之前的/cgi-bin/mapserv.exe

  7. 添加下述参数到 想要使用 FastCGI 连接的图层 layer:

    PROCESSING "CLOSE_CONNECTION=DEFER"
  8. 试用一下. 若成功的话,你可以在Windows Task Manager中看到,在与应用交互时, “mapserv.exe”进程是打开的

Notes:

  • in testing this was successful with PostgreSQL 9.0.4 / PostGIS 1.5.2, and with Oracle 10.2.0.1.0.
  • general MapServer and FastCGI notes can be found in the FastCGI Howto.

MapCache Apache 模块

The MapCache Apache module and the mapcache_seed.exe utility (as of MS4W 3.1.0) are included. In order to use the MapCache Apache module you must do the following:

  1. Open /ms4w/Apache/conf/httpd.conf in a text editor

  2. Uncomment line#180, and change to your correct path, such as:

    LoadModule mapcache_module "C:/ms4w/Apache/cgi-bin/mod_mapcache.dll"
  3. Around line#408 of your httpd.conf file you will see a “” section. Modify the path to the included MapCache configuration (XML) file, such as:

    <IfModule mapcache_module>
    <Directory "/ms4w/apps/mapcache/">
    AllowOverride None
    Options None
    Require all granted
    </Directory>
    MapCacheAlias /mapcache "C:/ms4w/apps/mapcache/mapcache.xml"
    </IfModule>
  4. Modify the mapcache.xml file. Please see the associated MapCache docs for assistance.

  1. Save your httpd.conf file and restart apache (execute /ms4w/apache-restart.bat)

  2. If the module was successfully loaded your /ms4w/Apache/logs/error.log file should contain a message similar to:

    [notice] Apache/2.4.18 (Win32) mod-mapcache/1.4.1 configured
    -- resuming normal operations
  3. Test your MapCache configuration by following steps in the associated MapCache testing docs

  4. The MapCache seeding utility is also included. To run the mapcache_seed.exe file be sure to first execute the /ms4w/setenv.bat file in your command window.

Notes:

  • this module was tested with the cache types: disk, sqlite, tiff, and berkeleyDB. You should follow the MapCache Cache Types docs for assistance, or contact Gateway Geomatics for assistance/custom builds/configurations.

  • the module was tested on Windows 7 and Vista; if you are using an older version of Windows and require this module you should consider upgrading, or contact Gateway Geomatics for assistance/custom builds/configurations. .

  • as this module is still in development, feedback is more than encouraged, it is required. Please send your MapCache questions to the MapServer-users mailing list. You are also encouraged to contact Gateway Geomatics directly for custom builds and to help fund the development and maintenance of MS4W.

使用 Python GDAL模块

Note:

> Python 2.6 is required for the Python GDAL module in
> MS4W, and you must have C:/python26 in your PATH to use
> the utilities.
>

Python GDAL 模块及其工具类位于 /ms4w/python/gdal/. 使用方法:

  1. 打开命令行窗口
  2. 切换到 ms4w 目录
  3. setenv.bat
  4. 执行Python工具,如:
> gdal_merge.py
>

gdal_merge.py notes:

  • -n (nodata_value) switch requires the NumPy module http://numpy.scipy.org/
  • raster_copy_with_nodata() also requires the NumPy module

Password Protection Configuration for Applications

The following section explains how to add password authentication to your MS4W application. However there are many other possible settings in Apache for this, so please consult the Apache HTTP Server documentation.

Here are the minimal steps for password protection:

  1. Modify your application’s httpd_xxx.conf file, so that “AllowOverride None” is replaced with “AllowOverride AuthConfig”, such as:

    Alias /gmap/ "/ms4w/apps/gmap/htdocs/"
    <Directory "/ms4w/apps/gmap/htdocs/">
    AllowOverride AuthConfig
    Options Indexes FollowSymLinks Multiviews
    Order allow,deny
    Allow from all
    </Directory>
  2. Create a password file.

    • open a DOS command window, and go to Apache’s bin directory

    • enter the following (replace “jeff” with the username you want to create, press ENTER and you will be prompted for a password to create):

      C:/ms4w/Apache/bin> htpasswd -c htpasswd.txt jeff
  3. 创建 htaccess 文件.

    • create a file in your application directory (/ms4w/apps/gmap/htdocs/ in this example) named ‘.htaccess’

    • the file should contain (you can modify it however you wish though):

      AuthType Basic
      AuthUserFile C:/ms4w/Apache/bin/htpasswd.txt
      AuthName "Password Required"
      require valid-user
  4. 重启 Apache

    • 执行/ms4w/apache-restart.bat
  5. Access your application in a web browser.

文章目录
  1. 1. MapServer之安装和基本使用
    1. 1.1. 概述
    2. 1.2. MS4W安装使用
      1. 1.2.1. 从旧版本升级
      2. 1.2.2. 应用组件
      3. 1.2.3. 全新安装
    3. 1.3. MapScript配置
      1. 1.3.0.1. Python
        1. 1.3.0.1.1. 安装 Python Mapscript 支持文件
      2. 1.3.0.2. 配置Apache运行Python脚本
        1. 1.3.0.2.1. 通过shebang 行
        2. 1.3.0.2.2. 通过 Apache directives(指令)
  2. 1.4. FastCGI
  3. 1.5. MapCache Apache 模块
  4. 1.6. 使用 Python GDAL模块
  5. 1.7. Password Protection Configuration for Applications
|