Resolving PHP Startup: Unable to load dynamic library PGSQL
When you encounter the error PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_pdo_pgsql.dll', it often feels contradictory. Your phpinfo() page clearly lists the PostgreSQL driver as enabled, and your application configuration expects it there. However, the underlying issue is a mismatch between where PHP looks for extensions and where the operating system actually places them.
This specific error message indicates that PHP attempted to load an extension at startup from a hardcoded path (/usr/lib/php/20151012/php_pdo_pgsql.dll) but failed because that file does not exist on the filesystem. The presence of .dll in the path is the first major red flag for developers running Linux distributions like Ubuntu 16.04. Windows uses DLL files as its standard executable format, whereas Linux systems rely on shared object files with the .so extension.
The error log explicitly states cannot open shared object file: No such file or directory. This confirms that the file expected by your PHP binary is missing entirely, not merely misconfigured. In many Linux environments, particularly those using PPA repositories or specific packaging managers, the PHP build may be compiled against headers for a .dll extension or inherited configuration from a Windows-centric toolchain, while the actual library installed via the package manager (like php7.0-pgsql) uses the standard .so format.
The Root Cause: Path and Extension Mismatch
The core of this problem lies in how PHP extensions are loaded on Linux versus Windows. When you see a path ending in .dll in an error log on Ubuntu, it usually means your php.ini file is referencing a non-existent file or the wrong file format.
On Ubuntu 16.04 with PHP 7.0, the correct extension file for PostgreSQL is typically named something like pdo_pgsql.so, located in /usr/lib/php/20151012/. If your configuration file points to php_pdo_pgsql.dll, you are asking the system to load a Windows binary on a Linux kernel.
To resolve this, you must ensure that your php.ini references the correct filename and location. Check the active configuration using:
php -i | grep pdo.pgsql
If the output shows the path ending in .dll, you need to locate the actual file provided by the package manager. You can find the correct extension file name using:
find /usr/lib/php/20151012/ -name "*pdo_pgsql*"
Once identified, update your php.ini or the specific .ini file loaded in that directory to reference the .so file instead. For example, change:
extension=php_pdo_pgsql.dll
to:
extension=pdo_pgsql.so
Handling Multiple PHP Versions and Binary Paths
The error message specifies /usr/lib/php/20151012/. This directory corresponds to the SAPI (Server API) built into PHP 7.0 specifically. However, modern setups often use php-fpm or CLI versions that might pull from slightly different paths depending on how they were installed.
If you are running Symfony 3.x with NGinx, ensure that the PHP binary being invoked by NGinx matches the one reporting the error. A common pitfall is mixing up the PHP binaries used for command-line operations versus those served by the web server. If your php.ini contains the incorrect extension path, it will apply to all entry points unless version-specific configuration files are used.
Sometimes, simply removing the erroneous line from php.ini allows PHP to skip loading that specific extension and fall back to searching the default paths defined by the extension_dir directive. If the driver is truly missing from the system packages, you might need to install it via:
sudo apt-get update
sudo apt-get install php7.0-pgsql
After installation, verify that the .so file now exists in the expected directory and that phpinfo() reflects the correct extension path without the .dll suffix.
Why This Matters for Doctrine DBAL
The downstream effect of this missing driver is visible in your Doctrine exceptions: could not find driver. Doctrine relies on the underlying PDO driver to establish a connection. If PHP fails to load the extension during its initialization phase (PHP Startup), Doctrine never gets an instance of the PDO PostgreSQL driver, resulting in a fatal exception when attempting to query the database.
Fixing the library path restores the bridge between your application logic and the database engine. Once the .so file is correctly referenced, PHP will successfully initialize the extension, allowing Doctrine to instantiate the PgSqlDriver and execute queries against your PostgreSQL instance without triggering startup warnings or driver exceptions.