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.
Tweet
comments
Thx! It’s work for me!
Good article! It’s work for me too!
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!
Thanks,
It works !!!
Also if apache is running you might have to restart it for the install to take effect.
sudo /etc/init.d/apache2 restart
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.
Thanks very very much!!! … just saved my day :)
Thank you Hero :)
Thanks a lot! I despaired of finding a solution, but you brought me back to life.
Thank you! you really solve my problem!
Thanks, you just saved me a couple of hours!
Works like a charm! Cheers!
Thank you, you save my time!!
It worked! Thanks a lot!
$ sudo apt-get install php5-sqlite did the trick. Thanks a lot!
Thanks. It works now!
Thanks. very thanks
Nope. Does not work in my ubuntu setup.
Thinks! I have been troubled by this problem for a whole day.
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).
Great post, thanks! I’ve fixed my problem
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”);
Great post. I’ve been chasing my tail for the past few hours. Now I found this and my problem is solved. Thanks!!
The command
apt-get –purge remove php5*
will do more harm than good on an established system, as it will remove all php modules loaded that might be required for other software.
Use the following command from the shell
$ php -m
to get the list of already installled modules PRIOR to the purge, and re-install them prior to the apt-get autoremove.
I installed LAMP Server with Ubuntu 12.04, but PDO sqlite support wasn’t included by default with LAMP Server on the Ubuntu (12.04) virtual machine. I found this post and it works for me as well. Thank you Greg and Prad!
Have one notice abaut: if you don’t like apache and use nginx or someting else where php-fpm used, – you must install this too:
sudo apt-get install php5-fpm
Thanks!! ………… :)