6

I'm trying to install the pdo-sqlite ext for the cli.

I have tried to run sudo apt-get install php5-sqlite and it says the ext is already up to date but when i run php -m it does not appear in the list.

In my /usr/lib/php/ folder I have 2 folders named 20131226 and 20160303. The latter one (20160303) contains pdo_sqlite.so but when i try to add this to the php.ini file i get the error

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/pdo_sqlite.so' - /usr/lib/php/20160303/pdo_sqlite.so: undefined symbol: zend_fetch_resource2_ex in Unknown on line 0

I am running ubuntu 14.04 and php 5.6.

Is anyone able to help with this problem? Also is anyone able to explain why the php extensions are stored in these different numbered folders and how php knows which one to look in? Thanks.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SamBremner
  • 793
  • 2
  • 10
  • 22

6 Answers6

10

I know this question has been answered, but other people might have the same problem as I did. I hope this helps someone, because I spent three f***ing days stuck on 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. 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 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 :)

IncrediblePony
  • 645
  • 9
  • 31
  • 2
    Accepted answer haven't helped me. Your answer is real good. You have saved my days. Thank you. – legale Jun 20 '20 at 20:55
4

You've got (at least part of) two different versions of php installed, and they're conflicting. You'll probably want to clean out the version you're not using in order to prevent further issues. It might be easiest to just wipe both and then reinstall the one you want. Also make sure that your php.ini has its extension_dir setting pointing to the correct directory for the version you're keeping.

The internal PHP API is versioned according to date, so when backwards-incompatible changes are made and a new version is required, you'll get a new subdirectory name. If the changes are backward-compatible, and no new API version is required, then you can make minor updates to your PHP version without having to recompile your extensions.

I believe 20131226 is for PHP version 5.6 and 20160303 is for PHP version 7.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • 1
    Thank you so much that worked! I wiped PHP completely from my system using this command: sudo aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "` and reinstalled php and all was fine. Thank you so much for your help and very informative answer :) – SamBremner Jun 22 '17 at 16:57
4

I tried to delete the library as mentioned in the previous comments and it worked for a short time then the problem came up again, so I did the following, when I deleted the library when doing ldd /usr/lib/php/20190902/pdo_sqlite. It appeared:

libsqlite3.so.0 => lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007fd35803b000)

and that link points in the same directory to libsqlite3.so.0.8.6

so replace the link in /usr/local/lib to point to this library as follows

sudo ln -sf /lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 /usr/local/lib/libsqlite3.so.0

sorry, I don't speak English so I use google translator

Alvarenga
  • 41
  • 4
2

you can try install php version 5 :

sudo apt install php5-sqlite3

or for another version :

PHP 7.1

sudo apt install php7.1-sqlite3

PHP 7.2

sudo apt install php7.2-sqlite3

PHP 7.3

sudo apt install php7.3-sqlite3

and another version you want....

nur zazin
  • 1,018
  • 13
  • 13
  • Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package php7.3-sqlite3 E: Couldn't find any package by glob 'php7.3-sqlite3' E: Couldn't find any package by regex 'php7.3-sqlite3' – Kardi Teknomo Nov 15 '21 at 13:28
1

This seems to be one of the few SO hits on PHP Startup: Unable to load dynamic library 'pdo_sqlite'. In my case, I don't actually use sqlite, but nonetheless see this error in my Apache logs.

The problem turned out to be a CGI script that was setting LD_LIBRARY_PATH (for unrelated reason) before calling PHP. This was somehow messing up PHP, possibly making it look in the specified LD_LIBRARY_PATH instead of the system paths. Unsetting LD_LIBRARY_PATH before calling PHP has fixed the problem.

Maksym
  • 1,430
  • 1
  • 11
  • 13
0

I had the same, for me the issue was in /etc/php/7.2/apache2/php.ini the outcomment was removed so pdo_sqlite was loaded (or tried to) from there too.

Modules are now loaded from /etc/php/7.2/apache2/conf.d/