简体   繁体   English

如何让mysql和php一起工作而不显示数据库密码

[英]How to make mysql and php work together and without show the database password

start mysql container启动mysql容器

$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

Connect to MySQL and manually create new database连接到 MySQL 并手动创建新数据库

$ docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

link the database and start php container链接数据库并启动php容器

$ docker run -d --link mysql:mysql --name myapp -v "$PWD":/var/www/html -p 80:80 php:5.6-apache

first question:第一个问题:

When access my php website: http://localhost/index.php , I got below error:当访问我的 php 网站: http://localhost/index.php 时,出现以下错误:

Fatal Error: Mysql is not supported in your PHP, recompile and try again.

Here is the configure command shows in phpinfo page, seems mysql module has been included in compile.这是phpinfo页面中显示的configure命令,似乎mysql模块已包含在编译中。

Configure Command './configure' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--with-apxs2' '--disable-cgi' '--enable-mysqlnd' '--with-curl' '--with-openssl' '--with-readline' '--with-recode' '--with-zlib'配置命令 './configure' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf .d' '--with-apxs2' '--disable-cgi' '--enable-mysqlnd' '--with-curl' '--with-openssl' '--with-readline' '--with-重新编码''--with-zlib'

Are there anything missed in official php image?官方 php 图像中是否遗漏了任何内容?

second question:第二个问题:

When access http://localhost/info.php , I can see phpinfo page.当访问http://localhost/info.php 时,我可以看到 phpinfo 页面。

But it also shows database password in session "Environment":但它也在会话“环境”中显示数据库密码:

MYSQL_ENV_MYSQL_ROOT_PASSWORD  my-secret-pw

and in session "PHP Variables"并在会话“PHP变量”中

_ENV["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]     my-secret-pw

So how to hide the password in phpinfo()?那么如何在phpinfo()中隐藏密码呢?

I assume you're trying to run phplist in a docker environment.我假设您正在尝试在 docker 环境中运行 phplist。

The message you're seeing ( Fatal Error: Mysql is not supported in your PHP, recompile and try again. ) is a phplist error message hardcoded in both the ./admin/mysql.inc and ./admin/mysqli.inc files.您看到的消息( Fatal Error: Mysql is not supported in your PHP, recompile and try again.并重Fatal Error: Mysql is not supported in your PHP, recompile and try again. )是./admin/mysql.inc./admin/mysqli.inc文件中硬编码的 phplist 错误消息。

This message is displayed upon check for the mysql_connect and mysqli_connect functions being present.在检查是否存在mysql_connectmysqli_connect函数时会显示此消息。 You are seeing this message because the functions are not present in your environment.您看到此消息是因为您的环境中不存在这些功能。

You have to find out what package offers this functionality and either install it on your docker image, or build a new docker image with this support present.您必须找出提供此功能的软件包,然后将其安装在您的 docker 映像上,或者构建一个具有此支持的新 docker 映像。

The official PHP docker image is based on Debian, which offers the php5-mysql package.官方 PHP docker 镜像基于 Debian,它提供了php5-mysql包。 This is not present in the docker image, so you install this package using apt-get , then use docker-php-ext-install , docker-php-ext-configure and docker-php-ext-enable to enable the mysql and mysqli extensions.这在 docker 映像中不存在,因此您使用apt-get安装此包,然后使用docker-php-ext-installdocker-php-ext-configuredocker-php-ext-enable启用mysqlmysqli扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM