3

I'm trying to install Spatialite (4.3.0a) on Ubuntu (14.94.2 LTS) ..... I'd like to use it with PHP (5.5.9-1) ....

Following this post

https://faimsproject.atlassian.net/wiki/display/FAIMS/Installing+Spatialite+4+on+Ubuntu

(obviously using the updated versions of the packages involved....), I've now installed:

  • PHP 5.5.9-1
  • SQLite 3.9.2
  • Proj4 4.9.2
  • Geos 3.5.0
  • Freexl 1.0.2
  • Spatialite 4.3.0a

I've also exported /usr/local/lib

export "LD_LIBRARY_PATH=/usr/local/lib"

It seems that SQLITE 3 and Spatialite are working fine ...

sqlite3 myDB
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> SELECT load_extension('mod_spatialite');

sqlite> SELECT sqlite_version();
3.9.2
sqlite> SELECT spatialite_version();
4.3.0a
sqlite> SELECT proj4_version();
Rel. 4.9.2, 08 September 2015
sqlite> SELECT geos_version();
3.5.0-CAPI-1.9.0 r4084
sqlite> .quit

But if I try to execute this simple PHP file

<html>
  <head>
    <title>Testing SpatiaLite on PHP</title>
  </head>
  <body>
    <h1>testing SpatiaLite on PHP</h1>

<?php
# connecting some SQLite DB
# we'll actually use an IN-MEMORY DB
# so to avoid any further complexity;
# an IN-MEMORY DB simply is a temp-DB 
$db = new SQLite3(':memory:');

# loading SpatiaLite as an extension
$db->loadExtension('/usr/local/lib/mod_spatialite.so');


# enabling Spatial Metadata
# using v.2.4.0 this automatically initializes SPATIAL_REF_SYS
# and GEOMETRY_COLUMNS
$db->exec("SELECT InitSpatialMetadata()");

# reporting some version info
$rs = $db->query('SELECT sqlite_version()');
while ($row = $rs->fetchArray())
{
  print "<h3>SQLite version: $row[0]</h3>";
}
$rs = $db->query('SELECT spatialite_version()');
while ($row = $rs->fetchArray())
{
  print "<h3>SpatiaLite version: $row[0]</h3>";
}

?>

  </body>
</html>

... the result is

testing SpatiaLite on PHP

SQLite version: 3.9.2

so it seems that somthing is going wrong with loading Spatialite.

My php.ini configuration is the follow

[sqlite]
 http://php.net/sqlite.assoc-case
sqlite.assoc_case = 0

[sqlite3]
sqlite3.extension_dir = /var/www/html/test/sqlite3_ext

In /var/www/html/test/sqlite3_ext there are

-rwxr-xr-x 1 cesare cesare 15527574 Dec  1 22:17 libspatialite.so
-rwxr-xr-x 1 cesare cesare 15944537 Dec  2 22:28 mod_spatialite.so
4
  • The spatialite.so should be in the sqlite extension directory, isn't it? On the following site you can find more info: gaia-gis.it/spatialite-2.4.0-4/splite-php.html – Zoltan Dec 8 '15 at 10:24
  • Yes Zoltan, I've followed those instructions ( there is an updated version now here ....gaia-gis.it/gaia-sins/spatialite-cookbook/html/php.html), and all the .so libraries are in sqlite extension directory ... but it stiil doesn't work – Cesare Dec 8 '15 at 10:32
  • But you load mod_spatialite from other dir: $db->loadExtension('/usr/local/lib/mod_spatialite.so'); Does this statement return TRUE? – Zoltan Dec 9 '15 at 6:09
  • I've tried to modify my code using $db->loadExtension('/var/www/html/test/sqlite3_ext/mod_spatialite.so'); but no news ...... When I try to execute the code from command line ... php Mytest.php ... the error is PHP Warning: SQLite3::loadExtension(): SQLite Extension are disabled in /var/www/html/test/MyTest.php – Cesare Dec 10 '15 at 21:20
2

I've solved putting

$db->loadExtension('mod_spatialite.so');

in my PHP code and configuring the LD_LIBRARY_PATH env variable in this way

export "LD_LIBRARY_PATH=/usr/local/lib" 

for execution from command line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.