[GRASS5] Grass with PHP (newbie question)

Glynn Clements glynn.clements at virgin.net
Tue Aug 17 10:48:02 EDT 2004


Namnath, Sharyn wrote:

> Thanks for your reply. Yes, I do mean running GRASS programs from a PHP
> script via "system" calls.  I've been playing with setting the environment
> variables, but it still doesn't work.  I tried doing a simple version call
> and piping it into a file.  The file gets created, but there is nothing
> inside of it.  It just creates a zero-length file.
> 
> Here is the code I'm using :
> 
> <?php
>   putenv("GISBASE=/Applications/Grass/grass53");
>   putenv("GISRC=/Users/administrator/.grassrc5");
>   putenv("GRASS_LOCATION=$location");
>   putenv("GRASS_PNGFILE=/Users/administrator/Sharyn.png");
>   putenv("DYLD_LIBRARY_PATH=/Applications/Grass/grass53/lib");
>   putenv("GRASS_TRUCOLOR=TRUE");
>   putenv("GRASS_PNG_COMPRESSION=0");
> 
>   system("env > /Users/administrator/Sites/click/environment_vars.txt");
>  
>   system("/Applications/Grass/grass53/bin/g.version > /Users/administrator/Sites/click/version_info.txt");
> ?>

Have you checked the server/PHP logs for error messages?

The attempt to run g.version may result in error messages being
written to stderr. I don't know how mod_php handles this, but anything
written to stderr by CGI scripts usually end's up in Apache's
error_log file.

Alternatively, you could redirect stderr directly, e.g.:

system(".../g.version > .../version_info.txt 2> .../version_errors.txt");

> The environment variables are echoed to the environment_vars.txt file just
> fine : 

> PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices

Yuo also need to add $GISBASE/bin and $GISBASE/scripts to PATH; some
GRASS programs run other GRASS programs/scripts; this will fail if
those directories aren't in $PATH.

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list