Skip to content

Add WORDPRESS_DB_SSL variable to support connection to the DB with TLS #558

New issue

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
WORDPRESS_DB_NAME
WORDPRESS_DB_CHARSET
WORDPRESS_DB_COLLATE
WORDPRESS_DB_SSL
"${uniqueEnvs[@]/#/WORDPRESS_}"
WORDPRESS_TABLE_PREFIX
WORDPRESS_DEBUG
Expand Down Expand Up @@ -137,12 +138,19 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
: "${WORDPRESS_DB_NAME:=wordpress}"
: "${WORDPRESS_DB_CHARSET:=utf8}"
: "${WORDPRESS_DB_COLLATE:=}"
: "${WORDPRESS_DB_SSL:=no}"

# version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
# https://github.com/docker-library/wordpress/issues/116
# https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
sed -ri -e 's/\r$//' wp-config*

if [ $WORDPRESS_DB_SSL == "yes" ]; then
WORDPRESS_CONFIG_EXTRA="
${WORDPRESS_CONFIG_EXTRA}
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);"
fi

if [ ! -e wp-config.php ]; then
awk '
/^\/\*.*stop editing.*\*\/$/ && c == 0 {
Expand Down Expand Up @@ -246,11 +254,12 @@ if (is_numeric($socket)) {
$user = getenv('WORDPRESS_DB_USER');
$pass = getenv('WORDPRESS_DB_PASSWORD');
$dbName = getenv('WORDPRESS_DB_NAME');
$flags = getenv('WORDPRESS_DB_SSL') === 'yes' ? MYSQLI_CLIENT_SSL : 0;

$maxTries = 10;
do {
$mysql = new mysqli($host, $user, $pass, '', $port, $socket);
if ($mysql->connect_error) {
$mysql = mysqli_init();
if (!$mysql->real_connect($host, $user, $pass, '', $port, $socket, $flags)) {
fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
--$maxTries;
if ($maxTries <= 0) {
Expand Down
13 changes: 11 additions & 2 deletions latest/php7.3/apache/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions latest/php7.3/fpm-alpine/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions latest/php7.3/fpm/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions latest/php7.4/apache/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions latest/php7.4/fpm-alpine/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions latest/php7.4/fpm/docker-entrypoint.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.