When you install php on a distribution, you cannot go to the last version of Sqlite because each distribution repository just does not update its library.
For instance, if you are on CentOs 7, you will stay at the version 3.7.17
And this version does not accept the json extension.
Below is a step by step guide that will show you how to create a sqlite shared library and update it on a CentOS 7 distribution.
PRAGMA compile_options;
In our case, we got the following compile option
DISABLE_DIRSYNC
ENABLE_COLUMN_METADATA
ENABLE_FTS3
ENABLE_RTREE
ENABLE_UNLOCK_NOTIFY
SECURE_DELETE
TEMP_STORE=1
THREADSAFE=1
# download
wget https://www.sqlite.org/2021/sqlite-amalgamation-3340100.zip
# unzip
unzip sqlite-amalgamation-3340100.zip
# cd
cd sqlite-amalgamation-3340100
gcc \
-Wl,-soname,libsqlite3.so.0 \
-DSQLITE_DISABLE_DIRSYNC \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_FTS3 \
-DSQLITE_ENABLE_RTREE \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_ENABLE_UNLOCK_NOTIFY \
-DSQLITE_SECURE_DELETE \
-DSQLITE_TEMP_STORE=1 \
-DSQLITE_DTHREADSAFE=1 \
-shared \
-o libsqlite3.so \
-fPIC \
sqlite3.c
To do this, we will first discover the process id (PID) with the ps command for a command with php.
ps -ef | grep php
root 3007 1 0 13:25 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www-user 3008 3007 1 13:25 ? 00:00:23 php-fpm: pool www
www-user 3009 3007 1 13:25 ? 00:00:30 php-fpm: pool www
lsof -p 30070 | grep sqlite
php-fpm 7993 root mem REG 8,1 33072 34216961 /usr/lib64/php/modules/pdo_sqlite.so
php-fpm 7993 root mem REG 8,1 753280 90544 /usr/lib64/libsqlite3.so.0.8.6
php-fpm 7993 root mem REG 8,1 54376 34216962 /usr/lib64/php/modules/sqlite3.so
systemctl stop php-fpm
mv /usr/lib64/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6.old
mv libsqlite3.so /usr/lib64/libsqlite3.so.0.8.6
systemctl start php-fpm
journalctl -u php-fpm
php --ri sqlite3
sqlite3
SQLite3 support => enabled
SQLite Library => 3.34.1
Directive => Local Value => Master Value
sqlite3.extension_dir => no value => no value
You may have forgotten the SQLITE prefix in the gcc command
NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'sqlite3' (tried: /usr/lib64/php/modules/sqlite3 )
The library and the php module seems to be hard-linked .
It means that the php module for instance /usr/lib64/php/modules/pdo_sqlite.so search the exact file /usr/lib64/libsqlite3.so.0.8.6.
Even LD_LIBRARY_PATH is not working. Be sure of the name of your file and of your path.