Bootstrap FreeKB - PHP - Enable PDO driver on Docker
PHP - Enable PDO driver on Docker

Updated:   |  PHP articles

This assumes you have installed the php:fpm container on Docker.

By default, the php:fpm image is configured so that only the sqllite PDO driver is enabled. For example, if you use the docker pull to pull down the latest php:fpm image.

docker pull php:fpm

 

And then use the docker run command is used to create and start the php fpm container.

docker run --detach --name php-fpm --publish 9000:9000 --restart unless-stopped php:fpm

 

Only the sqllite PDO driver will be enabled, which can be seen with the php -m command.

~]$ sudo docker exec php-fpm php -m | grep -i sql
sqlite3

 

Or at your phpinfo.php page.

 

Let's say you want to use the mySQL PDO driver. In this scenario, you could create a Dockerfile so that the Dockerfile contains something like this.

FROM php:fpm
RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable mysqli pdo_mysql

 

Then use the docker build command to create the image.

docker build . --tag php:fpm_mysqli_pdo

 

And then use the docker run command is used to create and start the php fpm container using the image that has the mySQL PDO driver enabled.

docker run --detach --name php-fpm --publish 9000:9000 --restart unless-stopped php:fpm_mysqli_pdo

 

Now the mySQL PDO driver should be enabled.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 858a2f in the box below so that we can be sure you are a human.