Docker Community Forums

Share and learn in the Docker community.

Your PHP installation appears to be missing the MySQL extension which is required by WordPress

docker
dockerhub

(Ericcheung) #1

I want to deploy my WordPress website on PHP/MySQL environment.

I use the official images.(php:5.6.16-apache and mysql:5.6.27)

Below is the command I used to start the container.

docker run --name wpdb01 -v /www/wp/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=wpdbzaq12wsx MYSQL_DATABASE=wpdb MYSQL_USER=wpadmin MYSQL_PASSWD=wpadmzaq12wsx -d mysql:5.6.27

docker run --name wpap01 -v /www/wp/web:/var/www/html -p:80:80 --link wpdb01:db -d php:5.6.16-apache

I unzip the WordPress package into /www/wp/web

After confirm both containers are running.I try to access the WP installation through browser.
http://wp01.exmaple.com/wordpress/wp-admin/setup-config.php

Finally,the below error threw out.
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

I’ve tried to add the below lines in php.ini file and restarted apache2 but it didn’t work .
extension=mysql.so
extension=pdo_mysql.so

Anyone can support me about this problem?

Maybe I need a php.ini file to configure the MySQL extension.


(Jeff Anderson) #2

The php image includes a couple scripts to help you install extensions in images build FROM the php image. Take a look at “How to install more PHP extensions” on https://hub.docker.com/_/php/.

Basically, you’ll create a Dockerfile that builds FROM this image. Next, you’ll apt-get install any dependencies needed for the mysql extension, and then use docker-php-ext-configure and docker-php-ext-install to actually install the extension.

Alternatively, there is an official wordpress image that is available as well: https://hub.docker.com/_/wordpress/.


(Ericcheung) #3

Hello Programmerq:

      Thanks for your reply about this problem and you're right that I miss to install the mysql extensions.No mysql.so exist in this container.

      I think I use a foolish way to solve this problem.

      I enter /usr/src/php/ext/mysql to generate mysql.so manually.
      1.root@c65017696ff0:/usr/src/php/ext/mysql# phpize 
      2.root@c65017696ff0:/usr/src/php/ext/mysql# ./configure 
      3.root@c65017696ff0:/usr/src/php/ext/mysql# make
      4.root@c65017696ff0:/usr/src/php/ext/mysql# make install
      5.root@c65017696ff0:#cp /usr/src/php/ext/mysql/modules/mysql.so /usr/src/php/ext
      6.Add 2 lines into /usr/local/etc/php/php.ini file
         extension=mysql.so
         extension_dir = /usr/src/php/ext
     7.Restart apache2
        apache2ctl -k restart

    Finally I commit the container to make a local PHP  image.

    Thank you .