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 https://github.com/sqlcipher/sqlcipher | |
#compile | |
cd sqlcipher | |
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" | |
make | |
#download php | |
cd /usr/local/src/ | |
wget https://www.php.net/distributions/php-7.4.9.tar.bz2 | |
#extract files | |
tar -xvjf php-7.4.9.tar.bz2 | |
#enter directory | |
cd php-7.4.9/ext/sqlite3 | |
#run phsize | |
phpize | |
#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 | |
make | |
#check module file sqlite3.so, if less than 110,000 byes, sqlcipher not included | |
ls -l modules/ -l | |
#another to check | |
strings modules/sqlite3.so | 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' | |
#to | |
pic_object='.libs/sqlite3.o /usr/local/src/sqlcipher/.libs/sqlite3.o' | |
#save file | |
#execute again | |
make | |
#check, if greateher thank 110,000 bytes, it linked ok | |
ls -l modules/ -l | |
#check strings, should be alot of functions | |
strings modules/sqlite3.so | grep cip | |
#copy compiled module tu modules, in php7.4 case the directory is /usr/lib/php/20190902/ | |
cp modules/sqlite3.so /usr/lib/php/20190902/ | |
#crear ini files to load in fpm, apache or cli, my case is cli and fpm | |
echo extension=sqlite3.so > /etc/php/7.4/cli/conf.d/20-sqlite3.ini | |
echo extension=sqlite3.so > /etc/php/7.4/fpm/conf.d/20-sqlite3.ini | |
#test php should giver versions in $version->fetchArray | |
<?php | |
$password = 'a'; | |
$db = new SQLite3('ad.db', SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); | |
print_r(SQLite3::version()); | |
$version = $db->query("PRAGMA cipher_version"); | |
if($version){ | |
var_dump($version->fetchArray()); | |
} 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