Building and Debugging PHPMapScript on Linux

Stephen Woodbridge wrote:

 > I have finally gotten around to trying to debug the
 > PHP3/Mapscript? problem I was having. You said I should
 > build PHP/Mapscript? as a static php CGI executable so I
 > can run it in gdb.

Actually, I meant compile PHP as a CGI executable instead of as an Apache DSO. And then you still compile PHP MapScript the same way, as a file that will be loaded by PHP at runtime.

Once you're all setup, you can debug a PHP script that crashes using the 'php' CGI executable in gdb with:

  $ gdb ./php
  (gdb) run /path/to/test.php

Here is the fun part: If you need to setup a breakpoint inside then you have to:

  • First set a breakpoint in php_dl()
  • start the program, when it reaches php_dl(), type "finish" to let php_dl() finish its execution
  • debugger will stop again at the end of php_dl(), after is loaded... then you can set breakpoints anywhere in and enjoy gdb! :)
  • Make sure you disable all breakpoints before re-running the program or gdb will keep complaining about them

There may be ways to automate this in gdb but I never looked into that any further... I welcome suggestions.

 > All the documentation only talks about building it as a DSO module for
 > apache. Can you send me a link or have someone add it to Wiki? I think
 > this would be a great help to aid others that might want to work with
 > PHP3 and Mapscript.

The answer to this question has been moved to a separate PHPMapScriptCGI page.

 > Also have you guys posted documentation on how to build Mapscript for
 > PHP4 and !MapServer 3.5? on Wiki?

Nothing special to say there... MapServer's configure takes care of it all on most platforms... here are some detailed steps (hopefully I didn't forget anything):

  1. Compile and install PHP as a CGI as described above
  1. Run configure in your mapserver dir. with the --with-php switch:

./configure --with-php=/path/to/php-src-that-you-just-compiled ...

  1. run 'make', that will automagically build mapserv, etc. ... and in mapserver/mapscript/php3
  1. Edit your php.ini and make sure extensions_dir is set to point to a valid location (e.g. /usr/local/lib/php4)
  1. Copy to your extensions_dir
  1. Make sure all libs used in your MapServer build are included in your runtime library path. See the PHP MapScript install FAQ about this common problem:
  1. You're ready to use dl(""); to load and use PHP MapScript in your PHP apps.

See also the PHPMapScript-install-HOWTO for more info:

Go back to: PHPMapScript

Last modified 12 years ago Last modified on Feb 1, 2012, 10:40:00 PM
Note: See TracWiki for help on using the wiki.