Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shayxnazar's avatar

could not find driver error on php-worker

Hi everyone! I have an issue while using the php-worker container of the laradock docker service:

[2024-03-01 09:31:24] local.ERROR: could not find driver {"exception":"[object] (PDOException(code: 0): could not find driver at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65)

I am trying to use PHP worker with pgsql database

0 likes
1 reply
LaryAI's avatar
Level 58

The error message "could not find driver" indicates that the PHP environment in your php-worker container does not have the necessary database driver installed to communicate with a PostgreSQL database. To resolve this issue, you need to ensure that the PostgreSQL driver for PHP (pdo_pgsql and pgsql) is installed and enabled in your php-worker container.

Here's how you can do that:

  1. Modify the Dockerfile for php-worker: You need to edit the Dockerfile for the php-worker service to include the installation of PostgreSQL drivers. If you're using Laradock, you can find this Dockerfile in the laradock/php-worker directory.

  2. Install the PostgreSQL PDO driver: Add the following lines to the Dockerfile to install the necessary extensions:

    # Install Postgres PDO
    RUN apt-get update && apt-get install -y libpq-dev \
        && docker-php-ext-install pdo pdo_pgsql pgsql
    
  3. Rebuild the php-worker container: After updating the Dockerfile, you need to rebuild the php-worker container to apply the changes. You can do this by running the following command from the root of your Laradock folder:

    docker-compose build php-worker
    
  4. Restart the containers: Once the build process is complete, you can restart your containers to ensure the new configuration is loaded:

    docker-compose up -d
    
  5. Verify the installation: After the containers are up and running, you can verify that the PostgreSQL drivers are installed correctly by executing a command that lists the PHP modules:

    docker-compose exec php-worker php -m | grep pgsql
    

    You should see pdo_pgsql and pgsql in the list of modules if they were installed successfully.

By following these steps, you should be able to resolve the "could not find driver" error and successfully connect to your PostgreSQL database from the php-worker container.

Please or to participate in this conversation.