about me about me
photography photography
software projects software projects
contact me contact me

I was surprised to find PDO sqlite support wasn’t included by default with PHP 5 on my Ubuntu (10.04) virtual machine. You can check which drivers are available with this small snippet of code (assuming you run this from the command line):

foreach (PDO::getAvailableDrivers() as $driver) {
    echo $driver . PHP_EOL;
}


Update: Long story short, I tried the following command on this web server and it worked without any hiccups. Try this first and see where it gets you, the rest of the article may dig you out of a hole if things break.

$ sudo apt-get install php5-sqlite

For whatever reason, my local Ubuntu VM I develop on had some issues, I originally wrote this blog post around the problems I encountered then.


I initially tried installing the php5-sqlite package:

$ sudo apt-get install php5-sqlite

This appeared to install successfully but did not enable the sqlite driver in PHP. I then tried to install the sqlite driver via PECL but this failed to install both pdo and pdo_sqlite.

$ sudo pecl install pdo
...
make: *** [pdo_dbh.lo] Error 1
ERROR: `make' failed
$ sudo pecl install pdo_sqlite
...
configure: error: Cannot find php_pdo_driver.h.
ERROR: `/tmp/pear/temp/PDO_SQLITE/configure' failed

Apparently this corrupts the current PDO install. What worked for me in the end:

$ 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

The third (commonly used libraries) and fourth (clean up) lines are optional.


You can skip to the end and leave a response. Pinging is currently not allowed.

comments

Sinope // 05.Aug.2011 // 10:13

Thx! It’s work for me!

Andre Linoge // 10.Aug.2011 // 18:45

Good article! It’s work for me too!

yoryer // 12.Aug.2011 // 05:36

Thank you for the article!
I’ve had problems installing the PDO extension for sqlite3 when I’m trying to use the Symfony framework on my VM with Ubuntu 11.04 and this works fine for me!

Groof // 07.Oct.2011 // 16:14

Thanks,
It works !!!

Trowalts // 20.Oct.2011 // 10:15

Also if apache is running you might have to restart it for the install to take effect.

sudo /etc/init.d/apache2 restart

bob // 04.Nov.2011 // 11:23

um, thanks. that –purge command wipes out a lot more than php. rips out your phpMyAdmin installation including any and all config settings you had… have to start from scratch now.

Aziz // 06.Nov.2011 // 07:51

Thanks very very much!!! … just saved my day :)

Doki // 19.Dec.2011 // 03:54

Thank you Hero :)

Serge // 04.Jan.2012 // 08:35

Thanks a lot! I despaired of finding a solution, but you brought me back to life.

Anteneh // 13.Feb.2012 // 11:09

Thank you! you really solve my problem!

Jean-Philippe // 20.Mar.2012 // 02:14

Thanks, you just saved me a couple of hours!

George // 31.Mar.2012 // 08:22

Works like a charm! Cheers!

Matteo // 12.Apr.2012 // 09:15

Thank you, you save my time!!

tons_1 // 13.Apr.2012 // 13:46

It worked! Thanks a lot!

jand // 25.Apr.2012 // 15:33

$ sudo apt-get install php5-sqlite did the trick. Thanks a lot!

ezau // 04.Jun.2012 // 09:52

Thanks. It works now!

sjkang // 18.Jun.2012 // 08:50

Thanks. very thanks

Doug Bird // 09.Aug.2012 // 00:23

Nope. Does not work in my ubuntu setup.

sophia // 27.Sep.2012 // 02:44

Thinks! I have been troubled by this problem for a whole day.

Dave Howler // 20.Nov.2012 // 15:05

A lot of people forget that restarting the server won’t always work.
Do a full stop and start after installing a module, you’ll save yourself some headaches. Sqlite did not work for me until I did ;)
apachectl stop
apachectl start
(or the like).

Fede // 10.Jan.2013 // 13:08

Great post, thanks! I’ve fixed my problem

Kirill // 10.Jan.2013 // 23:46

Just started with SQLite at Ubuntu. Not sure if this is my case. But I just did what you told but my php code didn’t create a db file…

$_db = new SQLiteDatabase(“gbook.db”);

Kevin // 07.Feb.2013 // 07:17

Great post. I’ve been chasing my tail for the past few hours. Now I found this and my problem is solved. Thanks!!