Sunday, April 09, 2006

Nona....it's Source

Source : Me at Nona

Step by step HowTo

Prerequisites ::
First, you obviously need a machine running Debian (sarge). To aquire source packages, you need to list a Debian source repository in your /etc/apt/sources.list - an example entry in this file could look like:

deb-src http://ftp.at.debian.org/debian/ sarge main

(please replace the hostname with your favourite Debian mirror). After you have added the line, perform an "apt-get update" to aquire the list of source packages (you need to become root for both adding the line and performing the update).
Create a working directory somewhere (eg. work/mapscript-compile/ in your home directory. You will need approx. 160MB of diskspace in this directory on the i386 architecture.
Installing the build dependencies ::
Both PHP and MapServer require a bunch of packages to be installed for the build process. Before you install those packages, you might want to keep a list of what got installed to be able to remove those unneccessary packages afterwards. I did a

apt-get -s build-dep php4 > builddep-php4-packages
apt-get -s build-dep mapserver > builddep-mapserver-packages
apt-get build-dep php4
apt-get build-dep mapserver
apt-get install fakeroot
apt-get install dpkg-dev
apt-get install php4-dev

to keep a record of the extra packages to be installed and install the packages (you need to perform those steps as root - the rest of the compilation can be done as an unprivileged user).
Downloading and (partly) building PHP4 ::
Since php_mapscript requires regex libraries from PHP4, we need to download and build PHP4 first:

$ apt-get source php4
$ cd php4-4.3.10
$ fakeroot dpkg-buildpackage

(Note: you don't need to wait for the build to complete - open a second shell, and watch the directory "apache-build/regex/.libs/" for appearance of the regex object files named "regcomp.o", "regerror.o", "regexec.o", "regfree.o". If those files exist, you can stop the build process - we just need those files)
Copy those files to the original PHP source tree:

$ cp apache-build/regex/.libs/*.o regex/

We have now prepared the PHP source tree to compile MapServer against in the next step:
downloading and building MapServer ::
We start with a plain MapServer build (you need to change directory one level up, so that we are in work/mapscript-compile/ again):

$ apt-get source mapserver
$ cd mapserver-4.4.1
$ fakeroot dpkg-buildpackage

We have now a "stock" MapServer package with no PHP mapscript support. However, we will work from the configure log output of the stock build to perform a custom build in the next step
re-configuring and rebuilding MapServer ::
The buildpackage process has left behind a config.log which includes the command to configure the package. Extract this command by issuing:

$ fgrep ./configure config.log > conf.new

Edit the "conf.new" file to remove the leading "$" sign, and add the following configure options to the end of the line (either avoid or esacpe line breaks - the resulting file should contain a single configure command):

--with-php=/usr/include/php4/
--with-php-regex-dir=../php4-4.3.10/regex/

Running this file should reconfigure MapServer to enable php_mapscript compilation, using the regex object files from the PHP source treee we created in the previous steps:

$ . ./conf.new

If you receive a warning about PHP and regex stuff doublecheck that you have properly copied the regex related objects file into the directory mentioned in the "with-php-regex-dir" option.
Start compilation with

$ make

If the build succeeds, you should have a MapScript PHP extension in mapscript/php3/php_mapscript.so (yes, it's for PHP4, just disregard the directory name). Strip unneccessary debugging symbols from the module, and install it into your PHP extensions directory:

$ strip --strip-unneeded mapscript/php3/php_mapscript.so
$ su
# cp mapscript/php3/php_mapscript.so /usr/lib/php4/20020429/

(you need to become root for the install step).
Testing the module ::
To test the module, put a simple test script (e.g. mapscript-test.php) into your web directory, containing eg.:



call it via a web browser, and check the phpinfo output for MapServer related stuff. Finished!

No comments:

Tanda Tangan