API Platform搭配SQLite提示找不到驱动的排查与解决
问题
我使用的是经过轻度修改的API Platform Symfony v4.0.11环境,由于内置的Postgres组件无法正常工作,转而使用SQLite作为数据库提供方。
在浏览器中加载Symfony应用的数据库关联页面时,出现错误:An exception occurred in the driver: could not find driver,这是因为Docker Compose默认未配置使用SQLite。
尝试安装驱动时遇到困难,我在Dockerfile中添加了以下内容但未成功:
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.com/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/*
执行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.org/debian bookworm InRelease 0.225 Hit:2 http://deb.debian.org/debian bookworm-updates InRelease 0.239 Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease 0.345 Ign:4 https://ppa.launchpadcontent.net/ondrej/php/ubuntu bookworm InRelease 0.372 Err:5 https://ppa.launchpadcontent.net/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.net/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
请问有什么方法可以成功安装该驱动(或功能等效的包)?
自答解决方法
后来意识到自己搞错了方向:我的应用是通过主机系统的symfony serve启动的,而非在Docker容器内。确认主机已安装php-sqlite3包后,只需取消php.ini文件中;extension=pdo_sqlite行的注释,重启symfony serve后问题就解决了!
内容的提问来源于stack exchange,提问作者Mayor of the Plattenbaus
相关产品推荐
相关产品推荐

