Skip to content

Instantly share code, notes, and snippets.

Last active March 24, 2023 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durich/bf15c091c6d59b042caa142950eaf252 to your computer and use it in GitHub Desktop.
Save durich/bf15c091c6d59b042caa142950eaf252 to your computer and use it in GitHub Desktop.
php 7.4 sqlcipher ubuntu php-sqlite3 with sqlcipher support
#this is for php 7.4 included in distro, may work in other versions of php 7
#install library
apt-get install php7.4-dev build-essential
#download and compile sqlcipher
cd /usr/local/src/
git clone
cd sqlcipher
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
#download php
cd /usr/local/src/
#extract files
tar -xvjf php-7.4.9.tar.bz2
#enter directory
cd php-7.4.9/ext/sqlite3
#run phsize
#copy m4 file
mv config0.m4 config.m4
#run configure
SQLITE_LIBS="/usr/local/src/sqlcipher/.libs/" SQLITE_CFLAGS="-I/usr/local/src/sqlcipher/ -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2" ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypt -L/usr/local/src/sqlcipher/.libs/" --libdir=/usr/local/src/sqlcipher/.libs/sqlite3.o
#run make
#check module file, if less than 110,000 byes, sqlcipher not included
ls -l modules/ -l
#another to check
strings modules/ | grep sqlcip
#include /usr/local/src/sqlcipher/.libs/sqlite3.o in the linking, this step is extra, because I'm noob on configure flags and c++ flags, suggestion are welcome
vim sqlite3.lo
#change line
pic_object='.libs/sqlite3.o /usr/local/src/sqlcipher/.libs/sqlite3.o'
#save file
#execute again
#check, if greateher thank 110,000 bytes, it linked ok
ls -l modules/ -l
#check strings, should be alot of functions
strings modules/ | grep cip
#copy compiled module tu modules, in php7.4 case the directory is /usr/lib/php/20190902/
cp modules/ /usr/lib/php/20190902/
#crear ini files to load in fpm, apache or cli, my case is cli and fpm
echo > /etc/php/7.4/cli/conf.d/20-sqlite3.ini
echo > /etc/php/7.4/fpm/conf.d/20-sqlite3.ini
#test php should giver versions in $version->fetchArray
$password = 'a';
$version = $db->query("PRAGMA cipher_version");
} else {
throw new Exception($db->lastErrorMsg());
$db->exec("PRAGMA key = '$password';");
$db->exec("PRAGMA cipher_page_size = 1024;");
$db->exec("PRAGMA kdf_iter = 64000;");
$db->exec("PRAGMA cipher_hmac_algorithm = HMAC_SHA1;");
$db->exec("PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment