how to enable sqlite3 for php?

PhpSqlite

Php Problem Overview


I am trying to install sqlite3 for PHP in Ubuntu.

I install apt-get php5-sqlite3 and edited php.ini to include sqlite3 extension.

When I run phpinfo(); I get

SQLITE3
SQLite3 support  enabled  
sqlite3 library version  3.4.2  

as shown above, sqlite3 is enabled. However, I get "Class SQLite3 not found" when I use

 new SQLite3("database");

Php Solutions


Solution 1 - Php

Try:

apt-get install php5-sqlite

That worked for me.

Solution 2 - Php

Edit: This answer is outdated, but can't be removed because it's accepted. Please see the solution from Stacey Richards for the correct answer.

 sudo apt-get install php5-cli php5-dev make
 sudo apt-get install libsqlite3-0 libsqlite3-dev
 sudo apt-get install php5-sqlite3
 sudo apt-get remove php5-sqlite3
 cd ~
 wget http://pecl.php.net/get/sqlite3-0.6.tgz
 tar -zxf sqlite3-0.6.tgz
 cd sqlite3-0.6/
 sudo phpize
 sudo ./configure
 sudo make
 sudo make install
 sudo apache2ctl restart

Ripped from the ubuntu form.

Solution 3 - Php

For PHP7, alter the below for your version of PHP (7.0, 7.2, 7.4, etc) and run

sudo apt-get install php7.0-sqlite3

and restart Apache

sudo apache2ctl restart

Solution 4 - Php

The accepted answer is not complete without the remainder of instructions (paraphrased below) from the forum thread linked to:

cd /etc/php5/conf.d

cat > sqlite3.ini
# configuration for php SQLite3 module
extension=sqlite3.so
^D

sudo /etc/init.d/apache2 restart

Solution 5 - Php

For Ubuntu 18.04 and PHP 7.2:

sudo apt install php-sqlite3

Solution 6 - Php

The SQLite3 PDO driver is named SQLite, not SQLite3, so you can do:

new SQLite("database");

For a SQLite2 database:

new SQLite2("database");

Solution 7 - Php

one thing I want to add , before you try to install

apt-get install php5-sqlite

or

apt-get install php5-sqlite3 

search the given package is available or not :-

 # apt-cache search 'php5'

After that you get :-

php5-rrd - rrd module for PHP 5

php5-sasl - Cyrus SASL extension for PHP 5

php5-snmp - SNMP module for php5

**php5-sqlite - SQLite module for php5**

php5-svn - PHP Bindings for the Subversion Revision control system

php5-sybase - Sybase / MS SQL Server module for php5

Here you get an idea about whether your version support or not .. in my system I get php5-sqlite - SQLite module for php5 so I prefer to install

**apt-get install php5-sqlite**


 

Solution 8 - Php

sudo apt-get install php5-cli php5-dev make

sudo apt-get install libsqlite3-0 libsqlite3-dev

sudo apt-get install php5-sqlite3

sudo apt-get remove php5-sqlite3

cd ~

wget http://pecl.php.net/get/sqlite3-0.6.tgz

tar -zxf sqlite3-0.6.tgz

cd sqlite3-0.6/

sudo phpize

sudo ./configure

That worked for me.

Solution 9 - Php

try this:

sudo apt-get --purge remove php5*
sudo apt-get install php5 php5-sqlite php5-mysql
sudo apt-get install php-pear php-apc php5-curl
sudo apt-get autoremove
sudo apt-get install php5-sqlite
sudo apt-get install libapache2-mod-fastcgi php5-fpm php5

Solution 10 - Php

In Centos 6.7, in my case the library file /usr/lib64/php/modules/sqlite3.so was missing.

yum install php-pdo 

vim /etc/php.d/sqlite3.ini
; Enable sqlite3 extension module
extension=sqlite3.so

sudo service httpd restart

Solution 11 - Php

Only use:

sudo apt-get install php5-sqlite

and later

sudo service apache2 restart

Solution 12 - Php

The Debian/Ubuntu way for php-7.2, php-7.3 & php-7.4 (e.g. the [234] part)

sudo apt install php7.[234]-sqlite
sudo phpenmod sqlite3

Be sure to note that on Windows Subsystem for Linux version 1 (WSL1) the (file-)locking system for SQlite is broken.

Solution 13 - Php

Depends on the version of PHP. For php7.0 the following commands work:
sudo apt-get install php7.0-sqlite3
then restart the Apache server:
sudo service apache2 restart

Solution 14 - Php

For Debian distributions. Nothing worked for until I added the debian main repositories on the apt sources (I don't know how were they removed): sudo vi /etc/apt/sources.list

and added

deb  http://deb.debian.org/debian  stretch main
deb-src  http://deb.debian.org/debian  stretch main

after that sudo apt-get update (you can upgrade too) and finally sudo apt-get install php-sqlite3

Solution 15 - Php

This will drown here, but I fixed my problems with this:

As far as I have found out, there is a faulty file in /usr/local/lib called libsqlite3.so.0 which points to libsqlite3.so.0.8.6. It's been installed through the php7.3-* packages as far as I can tell.

I renamed the file in case it was needed for something. With the command:

cd /usr/local/lib sudo mv libsqlite3.so.0 ./libsqlite3.so.0.back

But you can also just delete it: rm libsqlite3.so.0

The thread that lead me to the answer: link

This solved my problems, and I hope they solve yours as well :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMoonView Question on Stackoverflow
Solution 1 - PhpStacey RichardsView Answer on Stackoverflow
Solution 2 - PhpmiccetView Answer on Stackoverflow
Solution 3 - PhptheczechsensationView Answer on Stackoverflow
Solution 4 - PhpbtkView Answer on Stackoverflow
Solution 5 - PhpJarek JakubowskiView Answer on Stackoverflow
Solution 6 - PhpTom HaighView Answer on Stackoverflow
Solution 7 - PhpsanjeevView Answer on Stackoverflow
Solution 8 - PhpBitcoin MiningView Answer on Stackoverflow
Solution 9 - PhpHazem HagrassView Answer on Stackoverflow
Solution 10 - PhpsatishwinView Answer on Stackoverflow
Solution 11 - PhpC47View Answer on Stackoverflow
Solution 12 - PhpHenk PoleyView Answer on Stackoverflow
Solution 13 - PhpdoruView Answer on Stackoverflow
Solution 14 - Phpjavier_domenechView Answer on Stackoverflow
Solution 15 - PhpIncrediblePonyView Answer on Stackoverflow