-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfastcgi.html
More file actions
457 lines (413 loc) · 30.3 KB
/
fastcgi.html
File metadata and controls
457 lines (413 loc) · 30.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>FastCGI — MapServer 8.6.1 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx.css?v=48f05237" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="../_static/custom.css?v=dd298242" />
<link rel="stylesheet" type="text/css" href="../_static/ribbon.css?v=ea091bf4" />
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=ad95d4c4"></script>
<script src="../_static/doctools.js?v=fd6eb6e6"></script>
<script src="../_static/sphinx_highlight.js?v=6ffebe34"></script>
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../_static/copybutton.js?v=f281be69"></script>
<link rel="icon" href="../_static/mapserver.ico"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Limit Mapfile Access" href="limit_mapfile_access.html" />
<link rel="prev" title="Environment Variables" href="environment_variables.html" />
</head><body>
<!-- for main branch only, do not backport this -->
<table width="100%" style="width: 100%; background-color: white;">
<tr>
<td rowspan="2" style="padding: 10px 0px 10px 10px;">
<a href="../index.html" title="Home"><img src="../_static/banner.png" alt="MapServer banner" border="0" /></a>
</td>
<td style="padding: 10px 10px 0px 0px; text-align: right; vertical-align: top;">
<a href="../index.html" title="Home">Home</a> |
<a href="../products.html" title="Products (MapServer core, MapCache, TinyOWS">Products</a> |
<a href="https://github.com/mapserver/mapserver/issues/" title="Issue Tracker (MapServer core)">Issue Tracker</a> |
<a href="../community/service_providers.html" title="Professional Service Providers">Service Providers</a> |
<a href="../faq.html" title="Frequently Asked Questions">FAQ</a> |
<a href="https://fosstodon.org/@mapserver" title="Mastodon" target="_blank">Mastodon</a> |
<a href="../download.html" title="Download Source or Binaries">Download </a> |
<a class="badge" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KRJ2X44N3HA6U&source=url" target="_blank">
<img src="https://img.shields.io/badge/donate-%E2%9D%A4%C2%A0-ff69b4.svg?style=flat" alt="Donate to MapServer">
</a>
</td>
</tr>
<tr>
<td style="padding: 0px 10px 0px 0px; text-align: right; vertical-align: bottom;">
<img src="../_static/flagicons/en.png" alt="en" title="en" border="0" width="18px" height="13px"/>
<a href="../ar/optimization/fastcgi.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../de/optimization/fastcgi.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../el/optimization/fastcgi.html"><img src="../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../es/optimization/fastcgi.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../fr/optimization/fastcgi.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../id/optimization/fastcgi.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../it/optimization/fastcgi.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../ja/optimization/fastcgi.html"><img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../nl_NL/optimization/fastcgi.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../pl/optimization/fastcgi.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../ru/optimization/fastcgi.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../sq/optimization/fastcgi.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../tr/optimization/fastcgi.html"><img src="../_static/flagicons/tr.png" alt="tr" title="tr" border="0" /></a>
</td>
</tr>
</table>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="limit_mapfile_access.html" title="Limit Mapfile Access"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="environment_variables.html" title="Environment Variables"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.1 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Optimization</a> »</li>
<li class="nav-item nav-item-this"><a href="">FastCGI</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="fastcgi">
<span id="index-0"></span><span id="id1"></span><h1><a class="toc-backref" href="#table-of-contents" role="doc-backlink">FastCGI</a><a class="headerlink" href="#fastcgi" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Frank Warmerdam</p>
</dd>
<dt class="field-even">Contact<span class="colon">:</span></dt>
<dd class="field-even"><p>warmerdam at pobox.com</p>
</dd>
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Howard Butler</p>
</dd>
<dt class="field-even">Contact<span class="colon">:</span></dt>
<dd class="field-even"><p>hobu.inc at gmail.com</p>
</dd>
<dt class="field-odd">Last Updated<span class="colon">:</span></dt>
<dd class="field-odd"><p>2026-03-29</p>
</dd>
</dl>
<nav class="contents" id="table-of-contents">
<p class="topic-title">Table of Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#fastcgi" id="id2">FastCGI</a></p>
<ul>
<li><p><a class="reference internal" href="#introduction" id="id3">Introduction</a></p></li>
<li><p><a class="reference internal" href="#obtaining-the-necessary-software" id="id4">Obtaining the necessary software</a></p></li>
<li><p><a class="reference internal" href="#mod-fcgid-configuration" id="id5">mod_fcgid Configuration</a></p></li>
<li><p><a class="reference internal" href="#deprecated-mod-fcgi-configuration" id="id6">Deprecated mod_fcgi Configuration</a></p></li>
<li><p><a class="reference internal" href="#common-mod-fcgid-mod-fcgi-configuration" id="id7">Common mod_fcgid/mod_fcgi Configuration</a></p></li>
<li><p><a class="reference internal" href="#common-problems" id="id8">Common Problems</a></p></li>
<li><p><a class="reference internal" href="#fastcgi-on-win32" id="id9">FastCGI on Win32</a></p></li>
</ul>
</li>
</ul>
</nav>
<section id="introduction">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>FastCGI is a protocol for keeping cgi-bin style web applications running as a
daemon to take advantage of preserving memory caches, and amortizing other
high startup costs (like heavy database connections) over many requests.</p>
</section>
<section id="obtaining-the-necessary-software">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Obtaining the necessary software</a><a class="headerlink" href="#obtaining-the-necessary-software" title="Link to this heading">¶</a></h2>
<ol class="arabic simple">
<li><p>There are three pieces to the MapServer FastCGI puzzle. First, you need
the actual FastCGI library. This can be downloaded from
<a class="reference external" href="https://fastcgi-archives.github.io/">https://fastcgi-archives.github.io//</a>. This library does
the usual <em>configure, make, make install</em> dance. One added complication
is that it installs by default in /usr/local, and you might give the
<em>configure</em> command a –prefix=/usr to put it in a location that is
already visible to ldconfig.</p></li>
<li><p>Assuming you are running <a class="reference external" href="https://httpd.apache.org">Apache</a>, the next
piece you need is the fastcgi module. There are two fastcgi implementations
for apache:</p>
<ul class="simple">
<li><p><em>mod_fcgid</em>: mod_fcgid is the newer and recommended way to run fastcgi
programs under recent apache versions. It can be downloaded from the
<a class="reference external" href="https://httpd.apache.org/mod_fcgid/">Apache fcgid homepage</a></p></li>
<li><p><strong>deprecated</strong> <em>mod_fcgi</em>: Mod_fcgi depends on the version of Apache
you are running, so make sure to download the correct fork (Apache 1.3
vs. Apache 2).</p></li>
</ul>
</li>
<li><p>The third and final piece is to compile MapServer with FastCGI support.
This is pretty straightforward, and all you need to do is tell
<em>configure</em> where the FastCGI library is installed. If you changed
the prefix variable as described above, this would be:</p></li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">./</span><span class="n">configure</span> <span class="p">[</span><span class="n">other</span> <span class="n">options</span><span class="p">]</span> <span class="o">--</span><span class="k">with</span><span class="o">-</span><span class="n">fastcgi</span><span class="o">=/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span>
</pre></div>
</div>
<p>With those pieces in place, the MapServer CGI (mapserv) should now be
FastCGI-enabled. You can verify this by testing it on with the command line:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">hobu</span><span class="nd">@kenyon</span> <span class="n">mapserver</span><span class="o">-</span><span class="mf">6.2.0</span><span class="p">]</span><span class="c1"># ./mapserv -v</span>
<span class="n">MapServer</span> <span class="n">version</span> <span class="mf">6.2.0</span> <span class="n">OUTPUT</span><span class="o">=</span><span class="n">GIF</span> <span class="n">OUTPUT</span><span class="o">=</span><span class="n">PNG</span> <span class="n">OUTPUT</span><span class="o">=</span><span class="n">JPEG</span> <span class="n">OUTPUT</span><span class="o">=</span><span class="n">WBMP</span>
<span class="n">SUPPORTS</span><span class="o">=</span><span class="n">PROJ</span> <span class="n">SUPPORTS</span><span class="o">=</span><span class="n">FREETYPE</span> <span class="n">SUPPORTS</span><span class="o">=</span><span class="n">WMS_SERVER</span> <span class="n">SUPPORTS</span><span class="o">=</span><span class="n">WMS_CLIENT</span>
<span class="n">SUPPORTS</span><span class="o">=</span><span class="n">WFS_SERVER</span> <span class="n">SUPPORTS</span><span class="o">=</span><span class="n">WFS_CLIENT</span> <span class="n">SUPPORTS</span><span class="o">=</span><span class="n">FASTCGI</span> <span class="n">INPUT</span><span class="o">=</span><span class="n">EPPL7</span>
<span class="n">INPUT</span><span class="o">=</span><span class="n">SDE</span> <span class="n">INPUT</span><span class="o">=</span><span class="n">ORACLESPATIAL</span> <span class="n">INPUT</span><span class="o">=</span><span class="n">OGR</span> <span class="n">INPUT</span><span class="o">=</span><span class="n">GDAL</span>
<span class="n">INPUT</span><span class="o">=</span><span class="n">SHAPEFILE</span> <span class="n">DEBUG</span><span class="o">=</span><span class="n">MSDEBUG</span>
</pre></div>
</div>
</section>
<section id="mod-fcgid-configuration">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">mod_fcgid Configuration</a><a class="headerlink" href="#mod-fcgid-configuration" title="Link to this heading">¶</a></h2>
<ol class="arabic simple">
<li><p>Modify http.conf to load the FastCGI module.</p></li>
</ol>
<div class="highlight-apache notranslate"><div class="highlight"><pre><span></span><span class="nb">LoadModule</span><span class="w"> </span>fcgid_module<span class="w"> </span>modules/mod_fcgid.so
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>Add an Apache handler for FastCGI applications.</p></li>
</ol>
<div class="highlight-apache notranslate"><div class="highlight"><pre><span></span><span class="nb">AddHandler</span><span class="w"> </span>fcgid-script<span class="w"> </span>fcgi
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><p>Set FastCGI processing information</p></li>
</ol>
<div class="highlight-apache notranslate"><div class="highlight"><pre><span></span><span class="nt"><IfModule</span><span class="w"> </span><span class="s">mod_fcgid.c</span><span class="nt">></span>
<span class="w"> </span><span class="nb">FcgidMaxProcessesPerClass</span><span class="w"> </span><span class="m">30</span>
<span class="w"> </span><span class="nb">FcgidInitialEnv</span><span class="w"> </span>PROJ_DATA<span class="w"> </span><span class="sx">/usr/local/share/proj</span>
<span class="w"> </span><span class="nb">FcgidInitialEnv</span><span class="w"> </span>LD_LIBRARY_PATH<span class="w"> </span><span class="s2">"/usr/local/lib:/usr/local/pgsql/lib:/usr3/pkg3/oracle9/lib"</span>
<span class="nt"></IfModule></span>
</pre></div>
</div>
</section>
<section id="deprecated-mod-fcgi-configuration">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Deprecated mod_fcgi Configuration</a><a class="headerlink" href="#deprecated-mod-fcgi-configuration" title="Link to this heading">¶</a></h2>
<p>This section is left for reference. The recommended way to run fastcgi programs
under apache is to use mod_fcgid, as detailed above.</p>
<ol class="arabic">
<li><p>Modify http.conf to load the FastCGI module.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">LoadModule</span> <span class="n">fastcgi_module</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">apache</span><span class="o">/</span><span class="mf">1.3</span><span class="o">/</span><span class="n">mod_fastcgi</span><span class="o">.</span><span class="n">so</span>
</pre></div>
</div>
</li>
<li><p>Add an Apache handler for FastCGI applications.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">AddHandler</span> <span class="n">fastcgi</span><span class="o">-</span><span class="n">script</span> <span class="n">fcgi</span>
</pre></div>
</div>
</li>
<li><p>Set FastCGI processing information</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FastCgiConfig</span> <span class="o">-</span><span class="n">initial</span><span class="o">-</span><span class="n">env</span> <span class="n">PROJ_DATA</span><span class="o">=/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">proj</span>
<span class="o">-</span><span class="n">initial</span><span class="o">-</span><span class="n">env</span> <span class="n">LD_LIBRARY_PATH</span><span class="o">=/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">lib</span><span class="p">:</span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">pgsql</span><span class="o">/</span><span class="n">lib</span><span class="p">:</span><span class="o">/</span><span class="n">usr3</span><span class="o">/</span><span class="n">pkg3</span><span class="o">/</span><span class="n">oracle9</span><span class="o">/</span><span class="n">lib</span>
<span class="o">-</span><span class="n">appConnTimeout</span> <span class="mi">60</span> <span class="o">-</span><span class="n">idle</span><span class="o">-</span><span class="n">timeout</span> <span class="mi">60</span> <span class="o">-</span><span class="n">init</span><span class="o">-</span><span class="n">start</span><span class="o">-</span><span class="n">delay</span> <span class="mi">1</span>
<span class="o">-</span><span class="n">minProcesses</span> <span class="mi">2</span> <span class="o">-</span><span class="n">maxClassProcesses</span> <span class="mi">20</span> <span class="o">-</span><span class="n">startDelay</span> <span class="mi">5</span>
</pre></div>
</div>
</li>
</ol>
</section>
<section id="common-mod-fcgid-mod-fcgi-configuration">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Common mod_fcgid/mod_fcgi Configuration</a><a class="headerlink" href="#common-mod-fcgid-mod-fcgi-configuration" title="Link to this heading">¶</a></h2>
<ol class="arabic">
<li><p>Install a copy of the mapserv executable (originally <strong>mapserv</strong>
or <strong>mapserv.exe</strong>) into the cgi-bin directory with the extension
<strong>.fcgi</strong> (ie. <strong>mapserv.fcgi</strong>). Use this executable when you
want to utilize fastcgi support.</p>
<p>For some platforms, the MapServer link would then have to changed
from:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>http://your.domain.name/cgi-bin/mapserv?MAP=/path/to/mapfile.map
</pre></div>
</div>
<p>To:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>http://your.domain.name/cgi-bin/mapserv.fcgi?MAP=/path/to/mapfile.map
</pre></div>
</div>
<p>For other platforms, the MapServer link would then have to changed
from:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>http://your.domain.name/cgi-bin/mapserv.exe?MAP=/path/to/mapfile.map
</pre></div>
</div>
<p>To:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>http://your.domain.name/cgi-bin/mapserv.fcgi?MAP=/path/to/mapfile.map
</pre></div>
</div>
</li>
<li><p>In your mapfile, set a PROCESSING directive to tell FastCGI to cache
the connections and layer information on all layers for which connection
caching is desired - ie. all slow layers.</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">PROCESSING</span> <span class="s">"CLOSE_CONNECTION=DEFER"</span>
</pre></div>
</div>
</li>
</ol>
</section>
<section id="common-problems">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Common Problems</a><a class="headerlink" href="#common-problems" title="Link to this heading">¶</a></h2>
<section id="file-permissions">
<h3>File permissions<a class="headerlink" href="#file-permissions" title="Link to this heading">¶</a></h3>
<p>Fedora Core 3 doesn’t allow FastCGI to write to the process logs (when you
use RedHat’s Apache 2 rather than your own). This is described <a class="reference external" href="http://www.fastcgi.com/archives/fastcgi-developers/2005-March/003638.html">here</a>.</p>
<p>Also, FastCGI needs to write its socket information somewhere. This
can be directed with the <em>FastCgiIpcDir</em> directive.</p>
</section>
</section>
<section id="fastcgi-on-win32">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">FastCGI on Win32</a><a class="headerlink" href="#fastcgi-on-win32" title="Link to this heading">¶</a></h2>
<section id="ms4w-users">
<h3>MS4W Users<a class="headerlink" href="#ms4w-users" title="Link to this heading">¶</a></h3>
<p><a class="reference external" href="https://ms4w.com">MS4W (MapServer for Windows)</a> >= version 2.2.2 contains MapServer compiled
with FastCGI support. MS4W version >= 2.2.8 also contains the required Apache
module (mod_fcgid), and users must follow the <a class="reference external" href="https://www.ms4w.com/README_INSTALL.html#fastcgi">README instructions</a> to setup
FastCGI with their application.</p>
</section>
<section id="building-fcgi-2-4-0">
<h3>Building fcgi-2.4.0<a class="headerlink" href="#building-fcgi-2-4-0" title="Link to this heading">¶</a></h3>
<p>I used libfcgi-2.4.0 for use with Apache2 from <a class="reference external" href="https://fastcgi-archives.github.io/">https://fastcgi-archives.github.io/</a>.</p>
</section>
<section id="binary-io-patch">
<h3>Binary IO Patch<a class="headerlink" href="#binary-io-patch" title="Link to this heading">¶</a></h3>
<p>It is critical that stdio be in binary mode when PNG and other binary images
are written to it. To accomplish this for stdio handled through the FastCGI
library, I had to do the following hack to libfcgi/fcgi_stdio.c within the
fcgi-2.4.0 distribution.</p>
<p>In FCGI_Accept() made he following change</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="p">(</span><span class="n">isCGI</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">FCGI_stdin</span><span class="o">-></span><span class="n">stdio_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stdin</span><span class="p">;</span>
<span class="w"> </span><span class="n">FCGI_stdin</span><span class="o">-></span><span class="n">fcgx_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
<span class="w"> </span><span class="n">FCGI_stdout</span><span class="o">-></span><span class="n">stdio_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stdout</span><span class="p">;</span>
<span class="w"> </span><span class="n">FCGI_stdout</span><span class="o">-></span><span class="n">fcgx_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
<span class="w"> </span><span class="n">FCGI_stderr</span><span class="o">-></span><span class="n">stdio_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stderr</span><span class="p">;</span>
<span class="w"> </span><span class="n">FCGI_stderr</span><span class="o">-></span><span class="n">fcgx_stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
<span class="w"> </span><span class="cm">/* FrankWarmerdam: added so that returning PNG and other binary data</span>
<span class="cm"> will still work */</span>
<span class="cp">#ifdef _WIN32</span>
<span class="w"> </span><span class="n">_setmode</span><span class="p">(</span><span class="w"> </span><span class="n">_fileno</span><span class="p">(</span><span class="n">stdout</span><span class="p">),</span><span class="w"> </span><span class="n">_O_BINARY</span><span class="p">);</span>
<span class="w"> </span><span class="n">_setmode</span><span class="p">(</span><span class="w"> </span><span class="n">_fileno</span><span class="p">(</span><span class="n">stdin</span><span class="p">),</span><span class="w"> </span><span class="n">_O_BINARY</span><span class="p">);</span>
<span class="cp">#endif</span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
</pre></div>
</div>
<p>Also, add the following just before the FCGI_Accept() function</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#ifdef _WIN32</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><fcntl.h></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><io.h></span>
<span class="cp">#endif</span>
</pre></div>
</div>
<p>I’m sure there is a better way of accomplishing this. If you know how, please
let me know!</p>
</section>
<section id="building-libfcgi">
<h3>Building libfcgi<a class="headerlink" href="#building-libfcgi" title="Link to this heading">¶</a></h3>
<p>The makefile.nt should be fine. Just ensure you have run VCVARS32.BAT (as is
needed for building MapServer) and then issue the command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">nmake</span> <span class="o">/</span><span class="n">f</span> <span class="n">makefile</span><span class="o">.</span><span class="n">nt</span>
</pre></div>
</div>
<p>Then the .lib and .dll will be in libfcgi/Debug?. Make sure you copy the DLL
somewhere appropriate (such as your cgi-bin directory).</p>
</section>
<section id="other-issues">
<h3>Other Issues<a class="headerlink" href="#other-issues" title="Link to this heading">¶</a></h3>
<p>1) FastCGI’s receive a very limited environment on win32, seemingly even more
restricted than normal cgi’s started by apache. Make sure that all DLLs
required are either in the fastcgi directory or in windowssystem32. Any
missing DLLs will result in very cryptic errors in the error_log, including
stuff about Overlapping read requests failing or something like that.</p>
<p>2) Make sure you use a libfcgi.dll built against the same runtime library as
your mapserv.exe (and possibly libmap_fcgi.dll) or you will suffer a world of
pain! Different runtime libraries have different “environ” variables (as well
as their own stdio and heaps). You can check that everything is using
MSVCRT.DLL (or all using MSVCRTD.DLL) using the MS SDK Dependency Walker.</p>
</section>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script><h3>Navigation</h3>
<p>
<a href="../about.html" title="About">About</a><br>
<a href="../products.html" title="Products">Products</a><br>
<a href="../community/index.html" title="Community">Community</a><br>
<a href="../development/index.html" title="Development">Development</a><br>
<a href="../download.html" title="Downloads">Downloads</a><br>
<a href="../documentation.html" title="Documentation">Documentation</a><br>
<a href="../faq.html" title="FAQ">FAQ</a><br>
<a href="../psc.html" title="PSC">PSC</a><br>
<a href="https://fosstodon.org/@mapserver" title="Mastodon">Mastodon</a>
</p>
<h3>Current Table Of Contents</h3>
<ul>
<li><a class="reference internal" href="#">FastCGI</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#obtaining-the-necessary-software">Obtaining the necessary software</a></li>
<li><a class="reference internal" href="#mod-fcgid-configuration">mod_fcgid Configuration</a></li>
<li><a class="reference internal" href="#deprecated-mod-fcgi-configuration">Deprecated mod_fcgi Configuration</a></li>
<li><a class="reference internal" href="#common-mod-fcgid-mod-fcgi-configuration">Common mod_fcgid/mod_fcgi Configuration</a></li>
<li><a class="reference internal" href="#common-problems">Common Problems</a><ul>
<li><a class="reference internal" href="#file-permissions">File permissions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#fastcgi-on-win32">FastCGI on Win32</a><ul>
<li><a class="reference internal" href="#ms4w-users">MS4W Users</a></li>
<li><a class="reference internal" href="#building-fcgi-2-4-0">Building fcgi-2.4.0</a></li>
<li><a class="reference internal" href="#binary-io-patch">Binary IO Patch</a></li>
<li><a class="reference internal" href="#building-libfcgi">Building libfcgi</a></li>
<li><a class="reference internal" href="#other-issues">Other Issues</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="limit_mapfile_access.html" title="Limit Mapfile Access"
>next</a> |</li>
<li class="right" >
<a href="environment_variables.html" title="Environment Variables"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.1 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" >Optimization</a> »</li>
<li class="nav-item nav-item-this"><a href="">FastCGI</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">Copyright</a> 2026, Open Source Geospatial Foundation.
Last updated on 2026-03-30.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>