[mapserver-users] Couldn't run perl mapscript under Apache

Puneet Kishor pkishor at GeoAnalytics.com
Fri Nov 15 10:14:46 EST 2002


On Thursday, November 14, 2002, at 11:24  PM, krung wrote:

> Lowell.
>
> My script is very simple below;
>
> #!/usr/bin/perl -w
> use mapscript;
> use DBI qw/:standard/;
>
> print header();
> $map = new mapObj("test.map") or die "couldn't open map file\n";
> $img = $map->draw();
> $img->saveImage("images/test.png", $mapscript::MS_PNG,1,1,0);
> print "<IMG SRC=\"images/test.png\">";
>
>

try this...
=====================
#!/usr/bin/perl -w

# 1. import the modules
use CGI::Pretty qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use mapscript;
use DBI qw(:standard);

# 2. set dir and url paths
my $apppath = "/absolute/path/to/your/tmp/dir";
my $appurl = "/url/to/your/tmp/dir";

# set your mapfile
my $mapfile = "/absolute/path/to/your/mapfile";

# create a new map object
my $map = new mapObj("$mapfile") or die $mapscript::ms_error->{message};

# set a tmp map image name
my $imgname = $map->{name} . time() . ".png";

# create the map
my $img = $map->draw() or die('Unable to draw map');

# save the map
$img->saveImage($apppath . $imgname, $map->{imagetype}, 
$map->{interlace}, $map->{transparent}, $map->{imagequality});

# 3. output
print header, start_html;
print "<img src=$appurl/$imgname>";
print end_html;
=====================

now compare this with your script (I have only numbered the significant 
difference... rest is stylistic).

1. you didn't import the CGI modules (maybe you did, but didn't show it 
here... anyway).
2. the image has to be written to an absolute path by your perl script 
(perhaps not, but that is how I do it), but has to be retreived by your 
browser from a relative path. Defining the paths in variables at the 
top allows me to make changes to the paths without mucking around in 
the actual application.
3. print the correct headers and enders (you were missing your 
start_html).

In any case, set the paths (#2 above) correctly, making sure relative 
and absolute paths are correctly set. Also, verrrry important, make 
sure that your tmp directory is writable by Apache (you can check in 
your httpd.conf file what user apache runs as), or make the tmp 
directory `chmod 777 tmpdir`.

Of course, make sure your perl script is `chmod +x yourperlscript.pl` 
as well.

Most of this may be old hat for you, but I am covering all the bases.




More information about the mapserver-users mailing list