Is there a guidance to PHP for SQLCipher

530 views
Skip to first unread message

chen li

unread,
Mar 18, 2012, 1:02:21 AM3/18/12
to SQLCipher Users
hi, all.

I want to connect PHP sqlite with SQLCipher.

But it is hard to search related document, the only one i have is as
below:

http://groups.google.com/group/sqlcipher/browse_thread/thread/6d77e4ef2a1530d7
http://groups.google.com/group/sqlcipher/browse_thread/thread/f0282f9b8416ae7d/104bd0231d64229c?lnk=gst&q=php#104bd0231d64229c

but still for me, it is too hard to understand step by step.

Could anyone provide a guidance or a getting-started document for
SQLCipher in PHP?

Thanks very much!

chen li

unread,
Mar 23, 2012, 12:18:09 AM3/23/12
to SQLCipher Users
it is strange that no one answer my post...

On 3月18日, 下午1时02分, chen li <china.lic...@gmail.com> wrote:
> hi, all.
>
> I want to connect PHP sqlite with SQLCipher.
>
> But it is hard to search related document, the only one i have is as
> below:
>
> http://groups.google.com/group/sqlcipher/browse_thread/thread/6d77e4e...http://groups.google.com/group/sqlcipher/browse_thread/thread/f0282f9...

Nick Parker

unread,
Mar 23, 2012, 10:22:42 AM3/23/12
to sqlc...@googlegroups.com
Hi Chen,

It appears a common PHP configuration option is to build a shared
library and add a extension reference to it within the php.ini file [1],
[2]. If this is the case, you should be able to build a shared library
for sqlcipher and point your configuration to that instead. Could you
give that a try, we'd love to know if that works for you? Thanks!

1. http://www.php.net/manual/en/sqlite.installation.php#100554
2.
http://serverfault.com/questions/32982/how-do-i-enable-sqlite-on-linux-apache-php

On 3/22/12 11:18 PM, chen li wrote:
> it is strange that no one answer my post...
>

> On 3锟斤拷18锟斤拷, 锟斤拷锟斤拷1时02锟斤拷, chen li <china.lic...@gmail.com> wrote:
>> hi, all.
>>
>> I want to connect PHP sqlite with SQLCipher.
>>
>> But it is hard to search related document, the only one i have is as
>> below:
>>
>> http://groups.google.com/group/sqlcipher/browse_thread/thread/6d77e4e...http://groups.google.com/group/sqlcipher/browse_thread/thread/f0282f9...
>>
>> but still for me, it is too hard to understand step by step.
>>
>> Could anyone provide a guidance or a getting-started document for
>> SQLCipher in PHP?
>>
>> Thanks very much!

--
Nick Parker

chen li

unread,
Mar 27, 2012, 9:55:27 AM3/27/12
to SQLCipher Users
Dear NIck,

Thanks for your suggestion. i read it through and make install
SQLCipher in my linux. but i am not so familiar with linux, so still i
could not have SQLCipher on my php. below is my progress, could you
please help me?

1, i make install and i found below files in /usr/local/lib
pkgconfig/sqlite3.pc
libsqlite3.so.0.8.6
libsqlite3.so.0
libsqlite3.so
libsqlite3.la
libsqlite3.a

2, and i found below file as well
/usr/local/bin/sqlite3

3, then i add below line in php.ini
sqlite3.extension_dir = "/usr/local/lib"

but still, i could not work on SQLCipher...


On 3月23日, 下午10时22分, Nick Parker <npar...@zetetic.net> wrote:
> Hi Chen,
>
> It appears a common PHP configuration option is to build a shared
> library and add a extension reference to it within the php.ini file [1],
> [2]. If this is the case, you should be able to build a shared library
> for sqlcipher and point your configuration to that instead. Could you
> give that a try, we'd love to know if that works for you? Thanks!
>
> 1.http://www.php.net/manual/en/sqlite.installation.php#100554
> 2.http://serverfault.com/questions/32982/how-do-i-enable-sqlite-on-linu...
>
> On 3/22/12 11:18 PM, chen li wrote:
>
>
>
>
>
> > it is strange that no one answer my post...
>
> > On 3 18 , 1ʱ02 , chen li <china.lic...@gmail.com> wrote:
> >> hi, all.
>
> >> I want to connect PHP sqlite with SQLCipher.
>
> >> But it is hard to search related document, the only one i have is as
> >> below:
>
> >>http://groups.google.com/group/sqlcipher/browse_thread/thread/6d77e4e......

Nick Parker

unread,
Mar 27, 2012, 5:45:21 PM3/27/12
to sqlc...@googlegroups.com
Hi Chen,

Below are the step I went through to get PHP to recognize a sqlcipher
extension library. You might want to cross reference your steps to see
where they may differ. To begin with, I did this on a Ubuntu 11.10 VM.
This assumes you have the appropriate toolchain to build sqlcipher from
source (i.e., git, GNU compiler chain, OpenSSL).

Install Apache and PHP:
sudo apt-get install apache2
sudo apt-get install php5

Restart Apache:
sudo /etc/init.d/apache2 restart

Install php dev package for the phpize tool:
sudo apt-get install php5-dev

Build SQLCipher - only for the sqlite3.c file:
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC"
LDFLAGS="-lcrypto"
make

Download/extract PHP source (http://php.net/downloads.php) - I grabbed
the php-5.4.0.tar.bz2
tar xvfj php-5.4.0.tar.bz2

Build PHP enabled SQLCipher library
cd php-5.4.0/ext/sqlite3
phpize
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC"
LDFLAGS="-lcrypto"
cp [path to sqlcipher root directory]/sqlite3.c libsqlite
sed -i 's|PHP_FE_END|{NULL,NULL,NULL}|' sqlite3.c
make

The above steps will generate a file called sqlite3.so in the modules
directory. You then need to create an .ini file for the extension to be
loaded. On my machine, the directory that PHP monitors for
configurations was /etc/php5/apache2/conf.d. I created a file that
contained the following:

extension=/full/path/to/new/sqlite3.so

You will then want to restart Apache, if you create a PHP file that
contains the following, you should see information listed about the
sqlite extension being loaded by PHP.

<?php phpinfo(); ?>

Let us know if you're able to successfully build and configure this. Thanks!

--
Nick Parker

Reply all
Reply to author
Forward
0 new messages