skip to Main Content

Found a number of posts here with the same title, but I still can’t get this to work.

Got three docker containers running:
– one is running mysql
– one is running phpmyadmin (and it works perfectly with the mysql db)
– one is running php:apache, I created it like this:

docker run --network qrstampnet0 --name qrstampweb -d -v /var/qrstamp/www:/var/www/ -p 80:80 -p 443:443 php:apache

When running the following PHP script I get an error “Uncaught Error: Class ‘mysqli’ not found”:

$con->connection = new mysqli($mysql_db_hostname, $mysql_db_user, $mysql_db_password);

So I checked if with PHPInfo() and got the following results:

PHP version 7.4.4

Configure command: './configure' '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-libedit' '--with-openssl' '--with-zlib' '--with-pear' '--with-libdir=lib/x86_64-linux-gnu' '--with-apxs2' '--disable-cgi' 'build_alias=x86_64-linux-gnu'

Configuration File (php.ini) Path: /usr/local/etc/php

but this directory does not contain a php.ini file, only: php.ini-development and php.ini-production.

In the mysqlnd section it says:

loaded plugins: mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_caching_sha2_password,auth_plugin_sha256_password

and the following code, reports that mysqli is not loaded.

    if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'We don't have mysqli!!!';
} else {
    echo 'Phew we have it!';
}

I tried a lot of things, but can’t get this to work. Not sure what I’m missing….

2

Answers


  1. Chosen as BEST ANSWER

    Pfff, stupid.... For my running config I just had to copy the php.ini-production to php.ini. Stupid this was so simple. A little embarrassing :-) Took me 3hrs to figure out.


  2. Add this in your Dockerfile:

    RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
    

    Or run the image and execute inside your container:

    docker-php-ext-install mysqli 
    docker-php-ext-enable mysqli
    apachectl restart
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search