how to enable sqlite3 for php?
Asked Answered
C

17

99

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");
Ciccia answered 4/6, 2009 at 6:35 Comment(1)
Useful resource: zetcode.com/php/sqlite3Swede
Q
40

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.

Quarterdeck answered 4/6, 2009 at 6:51 Comment(5)
The 2nd to last command should be sudo checkinstall (after running sudo apt-get install checkinstall. Why use an OS with a package manager if you're not going to use it?Inshore
this is now out dated advice. e.g. forum.linode.com/viewtopic.php?p=39974Wage
Best advice for this understandably annoying situation: meta.stackoverflow.com/a/276564/2778484 and meta.stackexchange.com/questions/78438/… (fixing the answer with an edit is obviously not possible since it's beyond just a syntax error).Billbillabong
It is apt-get install php5-sqlite today as of 2015Neona
As of 2021: sudo apt-get install php-sqlite3Bethink
E
238

Try:

apt-get install php5-sqlite

That worked for me.

Earth answered 4/6, 2009 at 8:47 Comment(5)
the php5-sqlite3 package doesn't exist anymore.Wage
Or, in the case of CentOS, sudo yum install php-sqlite3 -yCoble
This also added a PHP configuration file in /etc/php5/apache2/conf.d; it even restarted Apache, although for some reason I had to restart it again for the change to take effect.Featherstone
Or, in case of Ubuntu 16.0.4 Xenial, sudo apt install php-sqlite3Maiolica
Good answer but I needed to restart apache to get the module to show up (eg. sudo service apache2 restart)Glovsky
E
45

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
Eccrinology answered 19/5, 2016 at 9:43 Comment(2)
for php 7.2 sudo apt-get install php7.2-sqliteAlejandro
E: Unable to locate package php7.3-sqlite3Ethbun
Q
40

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.

Quarterdeck answered 4/6, 2009 at 6:51 Comment(5)
The 2nd to last command should be sudo checkinstall (after running sudo apt-get install checkinstall. Why use an OS with a package manager if you're not going to use it?Inshore
this is now out dated advice. e.g. forum.linode.com/viewtopic.php?p=39974Wage
Best advice for this understandably annoying situation: meta.stackoverflow.com/a/276564/2778484 and meta.stackexchange.com/questions/78438/… (fixing the answer with an edit is obviously not possible since it's beyond just a syntax error).Billbillabong
It is apt-get install php5-sqlite today as of 2015Neona
As of 2021: sudo apt-get install php-sqlite3Bethink
A
16

For Ubuntu 18.04 and PHP 7.2:

sudo apt install php-sqlite3

Acrodont answered 26/2, 2019 at 12:58 Comment(1)
You mat need to execute apt-get update before the command above to make it executed with no errors.Buchheim
G
15

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
Gilthead answered 27/3, 2010 at 5:54 Comment(2)
I thought you also had to modify the php.conf file?Letsou
At least on Ubuntu 14.04, this step is not needed, as there already is a sqlite3.ini as /etc/php5/mods-available/sqlite3.iniAmong
B
5

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.

Brahmi answered 23/12, 2019 at 9:38 Comment(0)
A
4

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

new SQLite("database");

For a SQLite2 database:

new SQLite2("database");
Antoniettaantonin answered 4/6, 2009 at 8:21 Comment(0)
S
3

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**
Soubrette answered 10/2, 2015 at 10:26 Comment(0)
S
3

For Ubuntu 20.04 and PHP 8.2:

sudo apt update
sudo apt install php8.2-sqlite3
sudo phpenmod pdo_sqlite
sudo systemctl restart apache2
Suggestive answered 27/5, 2023 at 19:44 Comment(0)
G
2
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.

Gladsome answered 15/2, 2016 at 1:35 Comment(0)
C
1

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
Courses answered 24/1, 2013 at 9:36 Comment(3)
I guess OP needs to know some config changes. Just installing the required software doesn't answer the question.Booboo
Careful with these commands! While this could actually work it would be useful to inform that this will remove and purge all packages starting with "php5". In other words it will remove both core files and configuration files.Dandle
this worked for me!!! The cleaning out and then re installing all these things was good.... except for the second to last command install php-sqlite..... that's the same thing that happens in the 2nd command? Maybe it's needed in certain cases, but it didn't seem to do anything for mePestilent
C
1

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
Cordellcorder answered 10/8, 2016 at 5:46 Comment(0)
G
1

Only use:

sudo apt-get install php5-sqlite

and later

sudo service apache2 restart
Gaynell answered 25/5, 2018 at 18:33 Comment(0)
C
1

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

Crewelwork answered 4/3, 2019 at 14:33 Comment(0)
G
0

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

Goldagoldarina answered 29/1, 2019 at 15:21 Comment(0)
N
0

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 :)

Nedra answered 15/3, 2019 at 9:33 Comment(0)
P
0

make sure servers' php.ini file has extension=php_sqlite3.dll enabled and you have write rules for website root file

Parthenogenesis answered 3/10, 2022 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.