Docker+Ubuntu+Ambientum环境下PHP无法加载pdo_sqlite.so动态库问题
Hey there, let’s work through this PHP extension issue you’re facing after rebuilding your Docker containers. The error about missing zend_empty_string in pdo_sqlite.so is a clear sign that the extension isn’t compatible with your current PHP version in the container—here’s how to fix it:
1. Confirm the root cause first
Let’s verify the mismatch between your PHP version and the extension:
- Jump into your app container:
docker-compose exec app bash - Check your PHP version:
php -v - Try loading the extension directly to confirm the error:
php -d extension=pdo_sqlite.so -r "echo 'Test';"
You should see the same zend_empty_string error, which confirms the extension was compiled for a different PHP version than what’s running in your container.
2. Reinstall the pdo_sqlite extension to match your PHP version
If you’re using an official PHP Docker image, the easiest way is to use the built-in scripts to install the extension correctly:
- If you have a Dockerfile, add this line (adjust based on your PHP version, but this works for most official 7.x images):
RUN docker-php-ext-install pdo_sqlite - Rebuild your containers with:
docker-compose up --build --force-recreate
If you’re installing manually inside the container (good for quick testing, not recommended long-term):
apt-get update && apt-get install -y sqlite3 libsqlite3-dev docker-php-ext-install pdo_sqlite docker-php-ext-enable pdo_sqlite
3. Clean up old extension files (if needed)
Sometimes old, incompatible extension files linger. Let’s remove them before reinstalling:
- Find the location of the problematic extension:
find /usr/lib/php7 -name pdo_sqlite.so - Delete the file:
rm /path/to/pdo_sqlite.so
Then re-run the extension installation steps above.
4. Verify the fix
Once you’ve reinstalled the extension:
- Check if it’s loaded correctly:
php -m | grep pdo_sqlite
You should see pdo_sqlite listed.
- Test TNTSearch again—your PDOException about missing drivers should be gone.
- Run
docker-compose exec app composer update; the PHP startup warning should no longer appear.
5. Prevent this from happening again
- Avoid using
latesttags for your PHP image in Dockerfile—pin to a specific version likephp:7.4-fpmso you don’t get unexpected version updates. - Always use the official
docker-php-ext-*scripts to install extensions with official PHP images—they ensure extensions are compiled against the exact PHP version in the image.
内容的提问来源于stack exchange,提问作者Wagner Alkmim

