Failed loading mod_spatialite into PHP

940 views
Skip to first unread message

Sebastian Gerst

unread,
Sep 10, 2014, 8:36:28 AM9/10/14
to spatiali...@googlegroups.com
Hi,

I'm trying to load mod_spatialite to PHP using the test script from http://www.gaia-gis.it/spatialite-2.4.0-4/splite-php.html . I'm using a Windows 64bit environment with PHP 5.3.8

Then I modified php.ini restarted IIS and got an error like "The specific module could not be found".

After a lot of googling I found an hint to add the extension directory to the PATH environment variable. So I got this error message:


PHP Warning:  SQLite3::loadExtension() [<a href='sqlite3.loadextension'>sqlite3.loadextension</a>]: Die angegebene Prozedur wurde nicht gefunden.
 in D:\wwwroot\spatiallite_orig.php on line 16



Does anyone have an idea what I can do???

a.fu...@lqt.it

unread,
Sep 10, 2014, 11:01:57 AM9/10/14
to spatiali...@googlegroups.com
On Wed, 10 Sep 2014 05:36:28 -0700 (PDT), Sebastian Gerst wrote:
> After a lot of googling I found an hint to add the extension
> directory
> to the PATH environment variable. So I got this error message:
>
> PHP Warning: SQLite3::loadExtension() [sqlite3.loadextension [2]]:
> Die
> angegebene Prozedur wurde nicht gefunden.
> in D:wwwrootspatiallite_orig.php on line 16
>
> Does anyone have an idea what I can do???
>

Hi Sebastian,

my comprehension of the German language is very limited, anyway
I imagine that "Die angegebene Prozedur wurde nicht gefunden"
should probably correspond to "The specified procedure could
not be found".

I've absolutely no idea about the specific SQLite version
supported by PHP 5.3.8 for windows, but this seems to be a
rather obsolete version (probably released during 2011 or
2012). the most recent version is PHP 5.5.0 (2013)

there was a major change affecting load_extension() starting
since SQLite version 3.7.17 (May 2013), and mod_spatialite
is designed accordingly to the more recent specifications.
if you your PHP is actually using some archaic version of
SQLite (< 3.7.17) you can successfully load mod_spatialite
anyway, but in this case just specifying the module name is
not enough, you must specify the entry point as well:

SELECT load_extension('mod_spatialite', 'sqlite3_modspatialite_init');

OTH
Sandro

Sebastian Gerst

unread,
Sep 10, 2014, 11:39:36 AM9/10/14
to spatiali...@googlegroups.com
Hi Sandro,

Oh, sorry.  But you've translated the error message very well ;-)

First, my SQLite Version is 3.7.7.1. My spatialite version is 4.2.0

I've modified my php page and added the select load_extension() query like this:



$db = new SQLite3(':memory:');

# loading SpatiaLite as an extension

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

$db->exec("SELECT load_extension('mod_spatialite', 'sqlite3_modspatialite_init')");



Now I'm getting the following error:
PHP Warning:  SQLite3::exec() [<a href='sqlite3.exec'>sqlite3.exec</a>]: not authorized in D:\wwwroot\spatiallite_orig.php on line 19
I tried the load_extension() query before, but without the 'sqlite3_modspatialite_init' parameter. Got the same result.

Regards,
Sebastian




--
You received this message because you are subscribed to a topic in the Google Groups "SpatiaLite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spatialite-users/Bks_1cTu6KE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spatialite-users+unsubscribe@googlegroups.com.
To post to this group, send email to spatialite-users@googlegroups.com.
Visit this group at http://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.

a.fu...@lqt.it

unread,
Sep 10, 2014, 12:06:18 PM9/10/14
to spatiali...@googlegroups.com
On Wed, 10 Sep 2014 17:39:33 +0200, Sebastian Gerst wrote:
> Now I'm getting the following error:
>
> PHP Warning: SQLite3::exec() [sqlite3.exec [6]]: not authorized in
> D:wwwrootspatiallite_orig.php on line 19
>

bad news: a "not authorized" error practically means that the
PHP/sqlite3
connector's code intentionally forbids to load any extension.

I don't know if there is some configuration option allowing to
change this default behaviour; you can eventually try to ask the
same question on some forum or mailing list more spefifically
PHP-oriented.

bye Sandro

mj10777

unread,
Sep 11, 2014, 12:34:35 AM9/11/14
to spatiali...@googlegroups.com
On a Linux-System, this works correctly when using 'SQLite3'.
Problems can be run into when 'PDO' is being used
- http://stackoverflow.com/questions/8756146/how-to-load-sqlite-extension-in-pdo

Assuming that your original sqlite3 has been compiled with '--enable-dynamic-extensions' support.

Last week I built a php script to read RasterLite2 Data and it worked without a problem:

 $db = new SQLite3($db_name);
 $i_rc_raster=$db->loadExtension('mod_rasterlite2.so');
 $i_rc_spatial=$db->loadExtension('mod_spatialite.so');

So when doing this on a Windows machine, after replacing 'so' with 'dll', it should work if your version of Sqlite3 supports extension loading.

As Sando pointed out in his original php-sample, 'sqlite3.extension_dir' must be set in php.ini.

When I tried this the first time, the Sqlite3 version was showing an older version installed on the server.

After setting in php.ini:
[sqlite3]
sqlite3.extension_dir = /usr/local/lib


it switch to the present 3.8.* version, where the newer Sqlite3, Spatialite and RasterLite2 drivers where also installed.

So you must find out if:
- which Sqlite3 the IIS-Server (running PHP) is calling
-- if that Sqlite3 version supports extension loading
--- if not you must replace that version with one that does

---

For those interested, I found a simple php-script to read mbtiles with an OpenLayer script to show that it worked.

https://github.com/bmcbride/PHP-MBTiles-Server

Based on this and adapting Sandros sample I got a RasterLite2 version working

http://www.mj10777.de/application/rasterlite2.php?request=GetCapabilities

- will show (in Text form)
-- the version of Sqlite3, Spatialite and RasterLite2
-- the raster_coverages found and their extents (also transformed into wsg84)

http://www.mj10777.de/application/rasterlite2.php?db=rasterlite2/1910.berlin_karten.db&Layers=berlin_uebersichtsplan.1910&SRS=4326&BBOX=13.377227783,52.516220864,13.378601074,52.517056554

will extract an 256x256 Image of the given area from the RasterLite2 Database.

This script is, at the moment, very experimental - but it works with both Spatialite and RasterLite2.

Mark

Sebastian Gerst

unread,
Mar 11, 2015, 10:54:41 AM3/11/15
to spatiali...@googlegroups.com
Hi,

I'm trying to load the spatialite module with PHP on a Windows Server 2012, but it isn't working. On a Server 2008 it works fine. I've installed VS C++ Redistributables 2013, 2012 and 2008. So this can't be the problem...

PHP is executed on a command line as Administrator. So no authorizations issues happen. On the eventlog I'm getting the follwoing error:


Faulting application name: php.exe, version: 5.5.11.0, time stamp: 0x533c98b2
Faulting module name: libstdc++_64-6.dll, version: 0.0.0.0, time stamp: 0x5251958a
Exception code: 0xc0000005
Fault offset: 0x0000000000017618



Which says it must be libstdc++_64-6.dll throwing that error. Loading on command line with sqlite.exe works fine.


Does anybody has an idea???


Sebastian


--
You received this message because you are subscribed to a topic in the Google Groups "SpatiaLite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spatialite-users/Bks_1cTu6KE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spatialite-use...@googlegroups.com.
To post to this group, send email to spatiali...@googlegroups.com.

lydon_...@technologyonecorp.com

unread,
Oct 8, 2015, 5:45:43 AM10/8/15
to SpatiaLite Users
Hi Group,

We got the same error and the solution to the error loading spatialite 64bit in Windows Server 2012:

* Use the libstdc++_64-6.dll that comes with MinGW64 installation (replace the existing libstdc++_64-6.dll in modspatialite)

Got it working here:

Basically there MinGW64 DLL includes the functions that Windows Server 2012 requires (Windows Server 2008 does not require these).

If anybody knows how to find out which functions that Windows Server 2012 needs, please let us know.


Kind Regards,
Don

ParcoMontiSibillini

unread,
Mar 21, 2018, 11:27:28 AM3/21/18
to SpatiaLite Users

I group,

I have the same problem:
SQLite3::loadExtension(): Unable to open extensions outside the defined directory 

windows – apache 2.4 – php 5.6.34 nts fast cgi   x86.

 

 

Di seguito la nostra configurazione

php.ini

 

extension=php_sqlite3.dll

[sqlite3]

sqlite3.extension_dir = "C:/Program Files (x86)/Spatialite"

 

All’interno di tale directory sono presenti le dll mod_spatialite-4.4.0-RC0-win-amd64.7z  compreso quindi mod_spatialite.dll

 

Otteniamo l’errore:

SQLite3::loadExtension(): Unable to open extensions outside the defined directory in C:\Apache24\htdocs\testSpatiaLite\index.php on line 18

 

 

<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('db/dbtestspatialtite.db');

 

// loading SpatiaLite as an extension

 

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

// 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>";

}

 

Reply all
Reply to author
Forward
0 new messages