PHP inside NaviServer

http://naviserver.sourceforge.net/ns_logobig.gif

Source Code Downloads API Documentation Mailing Lists Bugs Developers


Naviserver and PHP5

To compile PHP as a module for Naviserver, you need:

 - installed Naviserver 4.99 or later - PHP 5.x or later

It has been tested with Drupal, RoundCube webmail, MailBee webmail, Mambo, Horder/IMP

Compiling PHP

 $ cd nsphp
 $ wget http://www.php.net/distributions/php-5.1.4.tar.gz
 $ tar -xzf php-5.1.4.tar.gz
 $ mkdir php-5.1.4/sapi/naviserver
 $ cp nsphp.c config.m4 php.sym php-5.1.4/sapi/naviserver
 $ cd php-5.1.4
 $ ./buildconf --force
 $ ./configure --with-naviserver <other options>
 $ make install
 $ cp libs/libphp5.so /usr/local/ns/bin

Alternatively, to build everything just type

 $ make build

and it will download and build libphp5.so and install it. By default it will install it into /usr/local/php and will copy libphp5.so into /usr/local/ns/bin

Changing nsd.tcl

Enabling PHP

Then enable the PHP module:

   ns_section  "ns/server/${server}/modules"
   ns_param    nsphp           ${home}/bin/libphp5.so

New section

Add a new section to pass options to PHP (required): The 'map' command will cause Naviserver to pass all requests to *.php to the PHP module (can be specified multiple times). Example:

   ns_section  "ns/server/${server}/module/nsphp"
   ns_param    map             *.php
   ns_param    map             *.php4

Calling PHP scripts from Tcl

 ns_php version
 Return PHP version

 ns_php eval string
 Evaluate PHP expression and return result

 ns_php evalfile filename
 Evaluate spacified PHP file

 ns_php call function
 Call PHP function and return result

Calling Tcl scripts from PHP

 ns_eval(Tcl_script);
 Evaluate Tcl code from PHP script and return result as string

 ns_log(severity,string);
 Put string in the server log, severity is one of 'Notice', 'Warning', 'Error', 'Debug', 'Fatal'

Naviserver, PHP5 and Zend Optimizer

The Zend Optimizer is an application for increasing the performance of PHP scripts. It is also necessary if you want to run PHP scripts where the source is encoded with the Zend Guard software. Scripts encoded with the latest Zend Guard Software release 4 need the Zend Optimizer release 3.x. The installation of the Zend Optimizer adds some lines to your PHP.ini config file to tell PHP to load the required Optimizer binaries. Once loaded you are also able to run Zend Guard encoded scripts with Naviserver.