0

I'm using the "php:7.1" docker image to setup the test environment for a new project. I get errors to while trying to use the

$db = new mysqli(...);

functions to acquire a DB connection.

I tried to use the docker image in interactive mode to find the necessary setup steps manually:

docker run -i -t php:7.1 /bin/bash

I run the following steps I found on the net to prepare the "mysqli" functions:

# update image
apt-get update
# install vim for local editing
apt-get install vim

I tried to install mysql from the following post: How to enable MySQLi extension in php 7?

apt-get install php-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php-mysql

I tried to activate the extension only but does not work because the extenstion does not exists:

extension=php_mysqli.dll

Error:

php info.php |grep mysql
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/php_mysqli.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20160303/php_mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
Configure Command =>  './configure'  '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--disable-cgi' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-curl' '--with-libedit' '--with-openssl' '--with-zlib'
mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
mysqlnd statistics =>

I have not an idea what I can do to get the extension installed and enabled.

Community
  • 1
  • 1
Konrad
  • 355
  • 4
  • 16
  • Try building your docker file using https://phpdocker.io/ -- it has a generator that allows you to tick the features you want, and get a working docker file out at the end. Really easy and avoids a lot of hassle. – Simba Feb 10 '17 at 11:36
  • dll is a windows stuff. for linux you need so – Your Common Sense Feb 10 '17 at 11:50
  • I used .so as extension. This was a copy/paste from the web site. – Konrad Feb 10 '17 at 12:41

1 Answers1

1

That's because you're doing it wrong. First thing MySQL extension, the old one, gets deprecated in PHP 7+. It doesn't exists on Debian based distros either. So what you need to do is create a Dockerfile with the following content:

FROM php:7.1
RUN docker-php-ext-install mysqli && \
    docker-php-ext-install pdo_mysql

And run the commands assuming you're in the directory where the Dockerfile lives :

docker build -t <some_tag> .
docker run -it <some_tag> bash

You will get into the prompt of your container and you can run then php -v the output should be something like:

# php -m
[PHP Modules]
...
mysqli ===> MySQLi has been installed
mysqlnd ===> MySQLnd has been installed
...
ReynierPM
  • 17,594
  • 53
  • 193
  • 363