Initial setup
These steps were checked on Ubuntu 10.10. Send us email with the results you had on different platforms.
Install Apache HTTP Server
$ sudo apt-get install apache2
Once the web server installation is done, PHP5 needs intalled also.
Install PHP5
$ sudo apt-get install php5 php5-dev libapache2-mod-php5 php5-curl php5-gd \
php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ps \
php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-xsl php5-common
Let's create a new PHP file to ensure everything is working:
$ sudo pico /var/www/test.php
Add this code to the file:
Restart Apache so all the prior changes get applied:
$ sudo /etc/init.d/apache2 restart
Now using a web browser point it to: http://localhost/test.php
Check if php works corectly.
Install Zorba
Get Zorba sources and follow Zorba Build Instructions.
Check Zorba is working.
$ zorba -q '2+1'
<?xml version="1.0" encoding="UTF-8"?>
3
Check php test is working.
$ ctest -R php
Start processing tests
Test project /tmp/zorba-1.2.0/build
1188/1188 Testing php Passed
100% tests passed, 0 tests failed out of 1
Passing the php test means that PHP5 is instlled corectly and there is a succesfull build that includes the PHP swig binding.
Enable Zorba extension in PHP
Copy Zorba extension library files to /usr/local/lib/php/.
zorba/build$ cp swig/php/zorba_api.so swig/php/zorba_api_wrapper.php /usr/local/lib/php/
Add the following lines to /etc/php5/apache2/php.ini file.
include_path="/usr/local/lib/php/"
extension=/usr/local/lib/php/zorba_api.so
Restart Apache Http server
$ sudo /etc/init.d/apache2 restart
Refresh browser: http://localhost/test.php
Check if zorba_api is in the list of php known extensions.
Verify it works
Add the following content to /var/www/zorba.php:
<html>
<title>Zorba test</title>
<body>
<?php
require_once 'zorba_api_wrapper.php';
$ms = InMemoryStore::getInstance();
$zorba = Zorba::getInstance($ms);
try {
$queryStr = '1+2';
$query = $zorba->compileQuery($queryStr);
$result = $query->execute();
echo $result;
$query->destroy();
$zorba->shutdown();
InMemoryStore::shutdown($ms);
} catch (Exception $e) {
die('ERROR:' . $e->getMessage());
}
?>
</body>
</html>
Point your browser to http://localhost/zorba.php and see the result.
Further reading
For more details on how to use Zorba API in PHP go to Building XQuery-powered applications with PHP and Zorba article by Vikram Vaswani.
Useful links
Install PHP 5, Apache 2 and MongoDB on Ubuntu 10.10
Building XQuery-powered applications with PHP and Zorba
Zorba build instructions