How to install pdo driver in php docker image?
Student asked me if it is necessary to simplify fractions at the end of answering a question. I’m not sure how to respond , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , 9 If using only MySQL, you can remove the PostgreSQL pdo_pgsql extension, which has additional requirements for installation. – mikkohei13 Oct 30 ’17 at 12:13 ,The official repository of PHP has a script called docker-php-ext-install https://github.com/docker-library/php/tree/master/5.6
Try do create a docker image like this:
FROM php:5.6-apache # PHP extensions RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql
Answer by Cara Reid
I am using as a base the php docker container with the tag:,I linked it with a basic mysql:5.6 image which I can reach at the host mysql. I created a DB, and filled a table with basic values.,Hence, I thought that the php container was lacking the php-mysql component I installed via:,When making connection via PHP (or any other), use the container’s name as host, which in case is learn-php-mysql.
I am using as a base the php docker container with the tag:
Yet trying to access my app, I get:
Fatal error: Uncaught exception 'PDOException' with message could not find driver' in /var/www/html/index.php:30 Stack trace: #0 [internal function]: PDO->__construct('mysql:host=mysq. ', 'root', 'root', Array) #1 [internal function]: PhalconDbAdapterPdo->connect(Array) #2 /var/www/html/index.php(30): PhalconDbAdapterPdo-__construct(Array) #3 [internal function]: () #4 [internal function]: PhalconDiService->resolve(NULL, Object(PhalconDiFactoryDefault)) #5 [internal function]: PhalconDi->get('db', NULL) #6 [internal function]: PhalconDi->getShared('db') #7 [internal function]: PhalconMvcModelManager->_getConnection(Object(Reviews), NULL) #8 [internal function]: PhalconMvcModelManager->getReadConnection(Object(Reviews)) #9 [internal function]: PhalconMvcModel->getReadConnection() #10 [internal function]: PhalconMvcModelMetaDataStrategyIntrospection->getMetaData(Object(Reviews), Object(PhalconDiFactoryDefault)) #11 [internal function]: PhalconMvcModelMetaData->_initialize(Object(Rev in /var/www/html/index.php on line 30
Hence, I thought that the php container was lacking the php-mysql component I installed via:
I also added a mysql.ini at:
cat /usr/local/etc/php/conf.d/mysql.ini ; configuration for php MySQL module ; priority=20 extension=pdo_mysql.so
If I echo phpinfo();die it tells me that:
Additional .ini files parsed: /usr/local/etc/php/conf.d/mysql.ini, /usr/local/etc/php/conf.d/phalcon.ini
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0 PDO PDO support => enabled PDO drivers => sqlite PDO Driver for SQLite 3.x => enabled
Answer by Randy Roman
You can replace pdo_mysql with pdo_pgsql if you are using Postgresql.,To install pdo inside a running docker container, run the following command in console of the docker container:,How to install pdo driver in php docker image?,If you are using official docker library of PHP, you should have a built-in script called docker-php-ext-install which can be used to install any PHP extension needed.
To install pdo inside a running docker container, run the following command in console of the docker container:
To install drivers for your selected database like MySQL as well, run :
docker-php-ext-install pdo pdo_mysql
To install pdo inside a running docker container, run the following command in console of the docker container:
FROM php:5.6-apache # PHP extensions RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql
Answer by Gia Carpenter
FROM php:5.6-apache RUN docker-php-ext-install pdo pdo_mysql COPY my-php-files/ /var/www/html/
Answer by Kylie Kerr
So anyone knows why it fails at installing pdo_mysql extension? Thanks.,RUN docker-php-ext-install pdo pdo_mysql,Can anyone reproduce this? The pdo_mysql extension builds fine for me here.,I’ve seen docker-php-ext-install mentioned in other issues, and have tried to use that:
docker exec -it docker-php-ext-install pdo pdo_mysql
Answer by Bowen Sheppard
If you need a CakePHP Docker Container with MySQL, I have created a Docker image for that purpose! No need to worry about setting it up. It just works!,I was suggested, not long ago, to change my code to use PDO in order to parameterize my queries and safely save HTML in the database.,I looked at http://php.net/manual/en/ref.pdo-mysql.php, and I don’t really get where I should put that $ ./configure —with-pdo-mysql string. Several years ago the MySQL team published a script to migrate to MySQLi. I don’t know if it can be customised, but it’s official.
Basically the answer from Jani Hartikainen is right! I upvoted his answer. What was missing on my system (based on Ubuntu 15.04) was to enable PDO Extension in my php.ini
extension=pdo.so extension=pdo_mysql.so
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I add pdo_mysql? #331
How can I add pdo_mysql? #331
Comments
I have an error when running Laravel5.
PDOException in Connector.php line 119: could not find driver
I checked which PDO driver is installed and found sqlite.
$ docker run -it php:7.0 php -r 'phpinfo();' | grep pdo pdo_sqlite
The text was updated successfully, but these errors were encountered:
I’m running a container without dockerfile, how would I do in this case? I would like to install «pdo_mysql» and «GD» php modules.
I’m running with the command:
docker run -d -p 3030:80 —name anchor-blog-1 -v «$PWD»:/var/www/html php:7.0-apache
@tghelere you could do that without a Dockerfile, but it’s going to be a pain: you’d need to write a command that install the modules and then starts apache. and it would need to do so each time you start the container..
docker run -d -p 3030:80 —name anchor-blog-1 -v «$PWD»:/var/www/html php:7.0-apache bash -c «docker-php-ext-install pdo_mysql gd; apache2-foreground» (not tested)
you have a to build a new image based on this one, and use this command in the Dockerfile:
RUN docker-php-ext-install pdo_mysql
take a look at more detailed documentation there : https://hub.docker.com/_/php/
I wasted alot of time trying to install pdo_mysql using apt-get, and forget that docker phalcon offers an easy way to do this by using docker-php-ext-install pdo_mysql
RUN docker-php-ext-install pdo_mysql
Footer
You can’t perform that action at this time.