admin管理员组

文章数量:1296914

I am using a lightly modified version of the API Platform Symfony environment. Since part of the postgres system built into that environment is not working for me right now, I'm falling back to using sqlite as the database provider.

I somewhat predictably get An exception occurred in the driver: could not find driver when loading any of my Symfony app's database-connected pages in the browser. That makes sense, since the docker compose setup is not by default configured to use sqlite.

What's surprising to me is how difficult it is to actually get the driver installed on the machine in question. Based on info seen in some other questions/answers, here's what I've tried adding to the Dockerfile, without success:

RUN apt update && apt upgrade -y
RUN apt-get install -y ca-certificates apt-transport-https
RUN apt-get install -y software-properties-common
RUN apt-get install -y python3-launchpadlib
RUN add-apt-repository  noble-updates/main
RUN add-apt-repository ppa:ondrej/php
RUN apt update
RUN apt upgrade
RUN apt install -y php7.3-sqlite3
RUN rm -rf /var/lib/apt/lists/*

Unfortunately, this yields the following output when doing a docker compose build --no-cache:

=> ERROR [php frankenphp_base  9/17] RUN apt update                                                                                                         0.8s
------
 > [php frankenphp_base  9/17] RUN apt update:
0.150 
0.150 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
0.150 
0.223 Hit:1  bookworm InRelease
0.225 Hit:2  bookworm-updates InRelease
0.239 Hit:3  bookworm-security InRelease
0.345 Ign:4  bookworm InRelease
0.372 Err:5  bookworm Release
0.372   404  Not Found [IP: 185.125.190.80 443]
0.452 Reading package lists...
0.763 E: The repository ' bookworm Release' does not have a Release file.
------
failed to solve: process "/bin/sh -c apt update" did not complete successfully: exit code: 100

Anybody know a sneaky way of getting this elusive package (or a functional equivalent) installed?

===

EDIT: I realized somewhat belatedly that I was barking up the wrong tree. My app was being served via symfony serve on my host system, not within the docker container. As soon as I realized that, I verified that the php-sqlite3 apt package had already been installed. After that, it was a simple matter of un-commentating the line in my php.ini file that said ;extension=pdo_sqlite and after a restart of my symfony serve command ... presto! Everything worked!

I am using a lightly modified version of the API Platform Symfony environment. Since part of the postgres system built into that environment is not working for me right now, I'm falling back to using sqlite as the database provider.

I somewhat predictably get An exception occurred in the driver: could not find driver when loading any of my Symfony app's database-connected pages in the browser. That makes sense, since the docker compose setup is not by default configured to use sqlite.

What's surprising to me is how difficult it is to actually get the driver installed on the machine in question. Based on info seen in some other questions/answers, here's what I've tried adding to the Dockerfile, without success:

RUN apt update && apt upgrade -y
RUN apt-get install -y ca-certificates apt-transport-https
RUN apt-get install -y software-properties-common
RUN apt-get install -y python3-launchpadlib
RUN add-apt-repository http://archive.ubuntu/ubuntu noble-updates/main
RUN add-apt-repository ppa:ondrej/php
RUN apt update
RUN apt upgrade
RUN apt install -y php7.3-sqlite3
RUN rm -rf /var/lib/apt/lists/*

Unfortunately, this yields the following output when doing a docker compose build --no-cache:

=> ERROR [php frankenphp_base  9/17] RUN apt update                                                                                                         0.8s
------
 > [php frankenphp_base  9/17] RUN apt update:
0.150 
0.150 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
0.150 
0.223 Hit:1 http://deb.debian./debian bookworm InRelease
0.225 Hit:2 http://deb.debian./debian bookworm-updates InRelease
0.239 Hit:3 http://deb.debian./debian-security bookworm-security InRelease
0.345 Ign:4 https://ppa.launchpadcontent/ondrej/php/ubuntu bookworm InRelease
0.372 Err:5 https://ppa.launchpadcontent/ondrej/php/ubuntu bookworm Release
0.372   404  Not Found [IP: 185.125.190.80 443]
0.452 Reading package lists...
0.763 E: The repository 'https://ppa.launchpadcontent/ondrej/php/ubuntu bookworm Release' does not have a Release file.
------
failed to solve: process "/bin/sh -c apt update" did not complete successfully: exit code: 100

Anybody know a sneaky way of getting this elusive package (or a functional equivalent) installed?

===

EDIT: I realized somewhat belatedly that I was barking up the wrong tree. My app was being served via symfony serve on my host system, not within the docker container. As soon as I realized that, I verified that the php-sqlite3 apt package had already been installed. After that, it was a simple matter of un-commentating the line in my php.ini file that said ;extension=pdo_sqlite and after a restart of my symfony serve command ... presto! Everything worked!

Share edited Feb 12 at 19:31 Mayor of the Plattenbaus asked Feb 11 at 21:56 Mayor of the PlattenbausMayor of the Plattenbaus 1,1605 gold badges40 silver badges79 bronze badges 7
  • Is there any specific reason that prevents you following the documented way how to install more php extensions? frankenphp.dev/docs/docker/#how-to-install-more-php-extensions – hakre Commented Feb 12 at 7:29
  • Good question. I have install-php-extensions pdo_sqlite in my list of commands that get run, but I still get the could not find driver message. So I believe there's still a dependency on another layer that's not being satisfied ;-) – Mayor of the Plattenbaus Commented Feb 12 at 7:47
  • Well, I'm unable to see the install-php-extensions pdo_sqlite command you're commenting about, but nevertheless, then probably the reason might be that the documentation there falls short because it hides the step to enable (activate) the module after installing. IIRC the docker-php-ext-enable <ext-name> should be called (via), please check. – hakre Commented Feb 12 at 8:45
  • I suspect it is the ini activation, however this is a bit of guessing. If you would share the base image it would be easier to answer with facts. Is there any reason that prevents you to provide the minimal reproducible example of the Dockerfile? – hakre Commented Feb 12 at 8:57
  • And just seeing on the FrankenPHP website: "Variants for PHP 8.2, 8.3 and 8.4 are provided." - php7.3-sqlite3 hints its not supported OOTB, so you may need to enable the extension of wish with both the PHP CLI and all the others SAPIs you want to make use of it. How are you testing it is enabled? Which SAPIs are you testing against? – hakre Commented Feb 12 at 9:14
 |  Show 2 more comments

1 Answer 1

Reset to default 1

For a PHP extension (module) to be available, it must

  • a) be installed (so the binary library is there, .so on Linux) and
  • b) the extension must be loaded (so the binary library is running with php).

Installing the binary:

install-php-extensions pdo_sqlite

Activating the binary (official PHP docker images):

docker-php-ext-enable pdo_sqlite

This is equivalent to using the systems package manager and telling PHP to load the ini-configuration with an extension=<ext-name> directive.

Some extensions that are Zend extensions need the zend_extension directive instead.

For PECL extensions, the pecl utility becomes the "package manager".


Now in your question you're making use of multiple things to install the extension and that is probably part of the confusion:

  • The systems package manager (apt-get)
  • Extending it with private repositories (ppa:ondrej/php)
  • The FrankenPHP PHP extension install script (install-php-extensions, via docker-php-extension-installer)

In case this is some kind of shotgun debugging, the install-php-extensions script should suffice. According to FrankenPHP #845 they build on-top the official PHP images and use docker-php-extension-installer which is also designed for official setups.

I'd isolate the case and use that script only without running the package managers etc. as it is originally outlined in the FrankenPHP documentation and see if it works.

If there are additional requirements via the package manager, I'd keep that separated and only when all things work in isolation, bring them more close together (if at all).


References

  • PHP: Description of core php.ini directives - Manual (php)
  • php - Official Image | Docker Hub (docker)
  • How to Install More PHP Extensions | Building Custom Docker Image | FrankenPHP: the modern PHP app server (frankenphp.dev)

本文标签: API Platform with sqlite Could not find driverStack Overflow