MySQL server has gone away

Hi Devilbox community,

I try to setup a php-mysql development environment.
i am very new using devilbox. Inside the docker I am able to connect to the mysql db. Now I try to setup a connection to connect hosted db outside of the docker.
The mysql server runs on port 3307.
I am not sure I set everything correctly because I get the above error:
MySQL server has gone away
Here is my settings:

index.php
<?php

$servername = "127.0.0.1:3307";
$username = "root";
$password = "mypassword";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

?>
.env

DEBUG_COMPOSE_ENTRYPOINT=2

DOCKER_LOGS=0


###
### Relative or absolute path to the devilbox repository.
### (Used as a prefix for all mount paths)
### There is no need to change this.
###
### The only exception is for OSX users wanting to use NFS
### mounts instead of Filesystem mounts due to degraded performance
### on OSX.
###
### Note: When changing this variable you must re-create the container.
###       Simply remove it, it will be auto-created during the next start:
###
### $ docker-compose rm -f
###
DEVILBOX_PATH=.


###
### At what IP address should the docker services listen
### on the Host computer?
###
### The specified default should be fine for Linux and OSX (127.0.0.1:).
### If you are on windows, you will probably have to change
### it to the IP address of the docker machine.
###
### a.) Leave blank, to listen on all interfaces (no trailing colon ':')
###    LOCAL_LISTEN_ADDR=
### b.) If an IP is specified, note the trailing colon ':'
###    LOCAL_LISTEN_ADDR=127.0.0.1:
###
LOCAL_LISTEN_ADDR=


###
### This is the domain suffix your projects will be made available
### with mass-virtual-hosting.
### It is also required for the internal DNS server to be setup.
###
### Note: In addition to period or dot character ('.'), only ALPHA ([a-zA-Z]+) characters are supported.
###
### Example:
###   TLD_SUFFIX=loc
### Makes your project available under xxxx.loc
###
### Example:
###   TLD_SUFFIX=local
### Makes your project available under xxxx.local
###
TLD_SUFFIX=loc


###
### Optional DNS configuration
### Allows you to add extra DNS records (above the wildcard entry)
### Useful if your host computer run other Docker services that you want to connect to or reach
### from within the Devilbox network by a custom hostname.
###
### Format:
### -------
### Resolve any custom defined hostname to an IP address (useable inside container and host os)
###     EXTRA_HOSTS=<hostname>=<ip>[,<hostname>=<ip>]
###
### Resolve any custom defined hostname to whatever IP address a CNAME resolves to
### (Useable inside the container and host OS).
### Note: CNAME must be resolvable by Google DNS
###     EXTRA_HOSTS=<hostname>=<CNAME>[,<hostname>=<CNAME>]
###
### Examples:
### ---------
### EXTRA_HOSTS=hostname.loc=1.2.3.4
### EXTRA_HOSTS=host.loc=1.2.3.4,host.example.org=3.4.5.6
EXTRA_HOSTS=


###
### Set your user id and group id
###
### This should be changed to the value of your local
### users uid and gid
###
### Type `id` on the terminal to find out your values
###
NEW_UID=4096
NEW_GID=4096


###
### Timezone for PHP Docker container (system and php.ini)
###
TIMEZONE=GMT



################################################################################
###
### INTRANET SETTINGS
###
################################################################################

###
### TLD_SUFFIX domains are checked if they are set in the
### host computer /etc/hosts or available via attached DNS server.
### Timeout is done on vhosts.php (intranet) via ajax calls.
### In order to keep performance, set this to a low value.
### DNS checks might not succeed in time on slow machines.
### If DNS is valid, but timeout is expired, set this to a higher value.
###
### DNS_CHECK_TIMEOUT value is how many seconds to time out
### Default is to timeout after 1 second (DNS_CHECK_TIMEOUT=1)
###
DNS_CHECK_TIMEOUT=1


###
### Devilbox UI SSL Certificate generation
###
### When using SSL each certificate requires names for which it is responsible:
### Common Name as well as alternative names.
###
### Specify comma separated hostnames below by which you want to access the Devilbox.
### Those hostnames will be included in the SSL certificate for the Devilbox intranet.
### This has nothing to do for SSL certificates for projects, it is just for the intranet
### itself.
###
DEVILBOX_UI_SSL_CN=localhost,*.localhost,devilbox,*.devilbox,httpd


###
### Devilbox UI Password protection enable/disable (1/0)
###
### Set DEVILBOX_UI_PROTECT to 1 in order to password protect the
### intranet.
###
### Example:
###   DEVILBOX_UI_PROTECT=1
###   DEVILBOX_UI_PROTECT=0
###
DEVILBOX_UI_PROTECT=0


###
### Devilbox UI Password
###
### When DEVILBOX_UI_PROTECT=1, use the following password
### to log in. The password can always be changed.
### When changing the password, make sure to restart your
### PHP container.
###
### Example:
###   DEVILBOX_UI_PASSWORD=my-very-secure-password
###   DEVILBOX_UI_PASSWORD=Some pass with spaces
###
### The default username is 'devilbox'
###
DEVILBOX_UI_PASSWORD=password


###
### Enable the Devilbox Intranet?
###
### Example:
###   DEVILBOX_UI_ENABLE=1
###   DEVILBOX_UI_ENABLE=0
###
DEVILBOX_UI_ENABLE=1


###
### Automatically be logged in into phpMyAdmin
###
### Example:
###   DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=1
###   DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=0
###
DEVILBOX_VENDOR_PHPMYADMIN_AUTOLOGIN=1


###
### Automatically be logged in into phpPgAdmin
###
### Example:
###   DEVILBOX_VENDOR_PHPPGADMIN_AUTOLOGIN=1
###   DEVILBOX_VENDOR_PHPPGADMIN_AUTOLOGIN=0
###
DEVILBOX_VENDOR_PHPPGADMIN_AUTOLOGIN=1



################################################################################
###
### 1. Choose Images (Version)
###
################################################################################

###
### You can choose any combination of httpd, mysql, postgresql or php.
### Each of them are fully compatible between one another.
###


###
### 1.1 Choose PHP Server Image
###
### Note: PHP 5.2 is not officially supported. Intranet won't work (due to lack of namespace support).
###       PHP 5.2 only works with Apache 2.4, Nginx stable and Nginx mainline.
###       Use at your own risk.
###
#PHP_SERVER=5.2
#PHP_SERVER=5.3
#PHP_SERVER=5.4
#PHP_SERVER=5.5
#PHP_SERVER=5.6
#PHP_SERVER=7.0
#PHP_SERVER=7.1
#PHP_SERVER=7.2
#PHP_SERVER=7.3
PHP_SERVER=7.4
#PHP_SERVER=8.0
#PHP_SERVER=8.1
#PHP_SERVER=8.2


###
### 1.2 Choose HTTPD Server Image
###
#HTTPD_SERVER=apache-2.2
#HTTPD_SERVER=apache-2.4
HTTPD_SERVER=nginx-stable
#HTTPD_SERVER=nginx-mainline


###
### 1.3 Choose MySQL Server Image
###
#MYSQL_SERVER=mysql-5.5
#MYSQL_SERVER=mysql-5.6
MYSQL_SERVER=mysql-5.7
#MYSQL_SERVER=mysql-8.0
#MYSQL_SERVER=mariadb-5.5
#MYSQL_SERVER=mariadb-10.0
#MYSQL_SERVER=mariadb-10.1
#MYSQL_SERVER=mariadb-10.2
#MYSQL_SERVER=mariadb-10.3
#MYSQL_SERVER=mariadb-10.4
#MYSQL_SERVER=mariadb-10.5
#MYSQL_SERVER=mariadb-10.6
#MYSQL_SERVER=mariadb-10.7
#MYSQL_SERVER=percona-5.5
#MYSQL_SERVER=percona-5.6
#MYSQL_SERVER=percona-5.7
#MYSQL_SERVER=percona-8.0

...


###
### 1.5 Choose Redis Server Image
###
### IMPORTANT: Alpine based images might cause issues on Docker Toolbox or OSX
###            https://github.com/docker/toolbox/issues/510
###
#REDIS_SERVER=2.8
#REDIS_SERVER=3.0
#REDIS_SERVER=3.0-alpine
#REDIS_SERVER=3.2
#REDIS_SERVER=3.2-alpine
#REDIS_SERVER=4.0
#REDIS_SERVER=4.0-alpine
#REDIS_SERVER=5.0
#REDIS_SERVER=5.0-alpine
REDIS_SERVER=6.0
#REDIS_SERVER=6.0-alpine
#REDIS_SERVER=latest
#REDIS_SERVER=alpine


###
### 1.6 Choose Memcached Server Image
###
### IMPORTANT: Alpine based images might cause issues on Docker Toolbox or OSX
###            https://github.com/docker/toolbox/issues/510
###
#MEMCD_SERVER=1.4
#MEMCD_SERVER=1.4-alpine
#MEMCD_SERVER=1.5
#MEMCD_SERVER=1.5-alpine
MEMCD_SERVER=1.6
#MEMCD_SERVER=1.6-alpine
#MEMCD_SERVER=latest
#MEMCD_SERVER=alpine


###
### 1.7 Choose Mongo Server Image
###
#MONGO_SERVER=2.8
#MONGO_SERVER=3.0
#MONGO_SERVER=3.2
#MONGO_SERVER=3.4
#MONGO_SERVER=3.6
#MONGO_SERVER=4.0
#MONGO_SERVER=4.2
MONGO_SERVER=4.4
#MONGO_SERVER=latest



################################################################################
###
### 2. Host Mounts (Your computer)
###
################################################################################

###
### Global mount options
###
### Note: When adding custom mount options, ensure to start with a
###       leading ',' (comma), as those options are prepended to already
###       existing mount options.
###
### Note: If no mount options are specified, leave this variable empty
###       and do not add a leading ',' (comma).
###
### MOUNT_OPTIONS=,cached
### MOUNT_OPTIONS=
###
### Example: Allow to share mounts accross container with SELINUX enabled
###
### MOUNT_OPTIONS=,z
###
MOUNT_OPTIONS=


###
### Local filesystem path to www projects.
###
### Note: When changing this variable you must re-create the container.
###       Simply remove it, it will be auto-created during the next start:
###
### $ docker-compose rm -f
###
HOST_PATH_HTTPD_DATADIR=./data/www


###
### Local filesystem path to where your backups are stored
###
### Note: When changing this variable you must re-create the container.
###       Simply remove it, it will be auto-created during the next start:
###
### $ docker-compose rm -f
###
HOST_PATH_BACKUPDIR=./backups


###
### The path on your host OS of the ssh directory to be mounted into the
### PHP container into /home/devilbox/.ssh.
###
### IMPORTANT: The path is mounted read-only to ensure you cannot accidentally
##             delete anything inside the php container.
###
HOST_PATH_SSH_DIR=~/.ssh



################################################################################
###
### 3. PHP Docker Settings
###
################################################################################

###
### Enable certain PHP modules which are not enabled by default
###
### Currently the only modules that can be enabled are 'ioncube' and 'blackfire'
### Also ensure to disable xdebug when using any of the above:
### https://xdebug.org/docs/install#compat
###
### PHP_MODULES_ENABLE=ioncube, blackfire
###
PHP_MODULES_ENABLE=


###
### Disable any PHP modules that you don't require
###
### Specify a comma separated list without spaces of modules to disable
###
### PHP_MODULES_DISABLE=xdebug,imagick,swoole
###
PHP_MODULES_DISABLE=oci8,PDO_OCI,pdo_sqlsrv,sqlsrv,rdkafka,swoole


###
### Postfix settings for email catch-all
###
### When set to '1' postfix is normally started and made available. However you still need
### to configure it to your needs yourself. For that you can use the autostart scripts
### and define a couple of 'postconf -e name=value' commands.
###
### When set to '2' (email catch-all), no mail will leave the Devilbox. It is automatically
### internally routed the the devilbox mail account and you can see each sent mail
### in the bundled intranet: https://localhost/mail.php
###
### Values:
### 0: Disable postfix (do not start it)
### 1: Enable/Start postfix
### 2: Enable/Start postfix and enable email catch-all
###
PHP_MAIL_CATCH_ALL=2


###
### Configure everything else about PHP in
### * cfg/php-ini-X.X/*.ini
### * cfg/php-fpm-X.X/*.conf



################################################################################
###
### 4. HTTPD Docker Settings
###
################################################################################

###
### Expose HTTPD Port to Host
###
HOST_PORT_HTTPD=80
HOST_PORT_HTTPD_SSL=443


###
### SSL (HTTP/HTTPS) settings for automated vhost generation
###
### By default each project will have two vhosts (one for HTTP and one for HTTPS).
### You can control the SSL settings for your projects via the below stated values.
###
### This is internally achieved via the '-m' argument of https://github.com/devilbox/vhost-gen
###
### Values:
###   * both:  Serve HTTP and HTTPS for all projects
###   * redir: HTTP always redirects to HTTPS
###   * ssl:   Only serve HTTPS
###   * plain: Only serve HTTP
###
HTTPD_VHOST_SSL_TYPE=both


###
### Document Root Subdirectory
###
### In your project directory, which subfolder should
### serve your files?
###
### When changing this value, restart the devilbox.
###
HTTPD_DOCROOT_DIR=htdocs


###
### Per vHost Config Subdirectory
###
### In your project directory, which subfolder should
### hold apache, nginx templates for a customized vhost?
###
### When changing this value, restart the devilbox.
###
HTTPD_TEMPLATE_DIR=.devilbox


###
### Webserver timeout (in seconds) to upstream PHP-FPM server
###
### This value should be greater than PHP's max_execution_time,
### otherwise the php script could still run and the webserver will
### simply drop the connection before getting an answer by PHP.
###
HTTPD_TIMEOUT_TO_PHP_FPM=180


###
### NGINX ONLY
###
### Set worker_processes and worker_connections
###
### https://nginx.org/en/docs/ngx_core_module.html#worker_processes
### https://nginx.org/en/docs/ngx_core_module.html#worker_connections
###
HTTPD_NGINX_WORKER_PROCESSES=auto
HTTPD_NGINX_WORKER_CONNECTIONS=1024



################################################################################
###
### 5. MySQL Docker Settings
###
################################################################################

###
### MySQL root user password
###
### The password is required for the initial creation of the MySQL database
### as well as the Devilbox intranet to display schema and configuration settings.
###
### If you change your MySQL root user password via mysql cli, phpMyAdmin or other tools
### after the database has been created, ensure to adjust the value here accordingly as well.
###
### If you only change this value here after the database has been created,
### the MySQL root user password will not actually be changed and the Devilbox intranet
### won't be able to connect to the MySQL service.
###
MYSQL_ROOT_PASSWORD=


###
### Expose MySQL Port to Host
###
HOST_PORT_MYSQL=3307



################################################################################
###
### 6. PostgreSQL Docker Settings
###
################################################################################

###
### PostgreSQL 'root' user name (usually postgres)
###
PGSQL_ROOT_USER=postgres


###
### PostgreSQL 'root' user password
###
### If you want to set a password, ensure to remove 'trust' from
### PGSQL_HOST_AUTH_METHOD below
###
PGSQL_ROOT_PASSWORD=


###
### In order to not use a password for PostgreSQL, keep this value at 'trust'
###
PGSQL_HOST_AUTH_METHOD=trust


###
### Expose PostgreSQL Port to Host
###
HOST_PORT_PGSQL=5432



################################################################################
###
### 7. Redis Docker Settings
###
################################################################################

###
### Expose Redis Port to Host
###
HOST_PORT_REDIS=6379


###
### Custom startup arguments
###
### Apply custom startup arguments to redis
###
### Example: Password protection
###   Add password protection to the Redis server by specifying it should
###   require a password.
###   Note: Do not add quotes or spaces to the password
###
###   REDIS_ARGS=--requirepass my-redis-root-password
###
### Example: Verbosity
###
###   REDIS_ARGS=--loglevel verbose
###
REDIS_ARGS=
#REDIS_ARGS=--loglevel verbose --requirepass my-redis-root-password



################################################################################
###
### 8. Memcached Docker Settings
###
################################################################################

###
### Expose Memcached Port to Host
###
HOST_PORT_MEMCD=11211



################################################################################
###
### 9. MongoDB Docker Settings
###
################################################################################

###
### Expose MongoDB Port to Host
###
HOST_PORT_MONGO=27017



################################################################################
###
### 10. Bind Docker Settings
###
################################################################################

###
### Expose Bind Port to Host
###
HOST_PORT_BIND=1053


###
### Add comma separated DNS server from which you want to receive DNS
### You can also add DNS servers from your LAN (if any are available)
###
BIND_DNS_RESOLVER=8.8.8.8,8.8.4.4


###
### Validate DNSSEC
###
### Values:
###  no:    DNSSEC validation is disabled
###  yes:   DNSSEC validation is enabled, but a trust anchor must be manually configured.
###  auto:  DNSSEC validation is enabled, and a default trust anchor for root zone is used.
###
BIND_DNSSEC_VALIDATE=no


###
### Bind timing options (time in seconds)
###
### Leave empty for defaults.
### Only change when you know what you are doing.
###
BIND_TTL_TIME=
BIND_REFRESH_TIME=
BIND_RETRY_TIME=
BIND_EXPIRY_TIME=
BIND_MAX_CACHE_TIME=


###
### Show DNS Queries in Docker logs output?
###
### 1: Yes
### 0: No
BIND_LOG_DNS_QUERIES=0



################################################################################
###
### 11. Custom variables
###
################################################################################

###
### Any variable defined in this file will be available
### as environment variables to your PHP/HHV Docker container.
###
### This might be useful to set application environment and retrieve
### them via: <?php getenv('MY_APPLICATION_ENV'); ?>
###


###
### Example:
### <?php echo getenv('Foo'); ?> would produce: 'some value'
###
#Foo=some value
#EXTRA_HOSTS='overwatch.loc=host.docker.internal:3307'
docker-compose.yml
---
##
## -------------------------
## |  D E V I L S T A C K  |
## -------------------------
##
## Local LAMP/LEMP stack
##
##
## ${VARIABLE:-default} will evaluate to default if VARIABLE is unset or empty.
## ${VARIABLE-default}  will evaluate to default only if VARIABLE is unset.
##
##
## -- DO NOT EDIT THIS FILE --
##
## Copy 'docker-compose.override.yml-example' to 'docker-compose.override.yml'
## and edit this file with your custom changes (override or even new services).
##
## Edit '.env' for configuration.
##
## If '.env' does not exist, copy 'env-example' to '.env'
##   $ cp env-example .env
##

version: '2.3'


################################################################################
# SERVICES
################################################################################
services:

  # ------------------------------------------------------------
  # Bind (DNS Server)
  # ------------------------------------------------------------
  bind:
    image: cytopia/bind:0.15
    hostname: bind
    restart: always
    ports:
      # [local-machine:]local-port:docker-port
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_BIND:-1053}:53/tcp"
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_BIND:-1053}:53/udp"

    environment:
      ##
      ## Debug?
      ##
      - DEBUG_ENTRYPOINT=${DEBUG_COMPOSE_ENTRYPOINT}

      ##
      ## Bind wildcard/host settings
      ##
      - WILDCARD_DNS=${TLD_SUFFIX:-loc}=127.0.0.1
      - EXTRA_HOSTS=${EXTRA_HOSTS}

      ##
      ## Forwarding
      ##
      - DNS_FORWARDER=${BIND_DNS_RESOLVER:-8.8.8.8,8.8.4.4}

      ##
      ## Security
      ##
      - DNSSEC_VALIDATE=${BIND_DNSSEC_VALIDATE:-no}

      ##
      ## Time settings
      ##
      - TTL_TIME=${BIND_TTL_TIME}
      - REFRESH_TIME=${BIND_REFRESH_TIME}
      - RETRY_TIME=${BIND_RETRY_TIME}
      - EXPIRY_TIME=${BIND_EXPIRY_TIME}
      - MAX_CACHE_TIME=${BIND_MAX_CACHE_TIME}

      ##
      ## Query log
      ##
      - DOCKER_LOGS=${BIND_LOG_DNS_QUERIES}

    dns:
      - 127.0.0.1

    # MacOS and Windows have this by default, this hack also allows it for Linux
    extra_hosts:
      docker.for.lin.host.internal: 172.16.238.1
      docker.for.lin.localhost: 172.16.238.1

    networks:
      app_net:
        ipv4_address: 172.16.238.100


  # ------------------------------------------------------------
  # PHP
  # ------------------------------------------------------------
  php:
    image: devilbox/php-fpm:${PHP_SERVER}-work-0.134
    hostname: php

    ##
    ## All .env variables
    ##
    ## Source all variables defined in .env
    ## This also makes any custom variable available in each PHP/HHVM container
    ##
    env_file:
      - ./.env

    environment:
      ##
      ## Debug/Logging
      ##
      - DEBUG_ENTRYPOINT=${DEBUG_COMPOSE_ENTRYPOINT}
      - DEBUG_COMPOSE_ENTRYPOINT
      - DOCKER_LOGS

      ##
      ## Tools
      ##
      - COMPOSER_MEMORY_LIMIT=-1

      ##
      ## UserID and GroupID
      ##
      - NEW_UID
      - NEW_GID

      ##
      ## Adjust timezone
      ##
      - TIMEZONE

      ##
      ## Enable/Disable PHP Modules
      ##
      - ENABLE_MODULES=${PHP_MODULES_ENABLE}
      - DISABLE_MODULES=${PHP_MODULES_DISABLE}

      ##
      ## Mail-catching
      ##
      - ENABLE_MAIL=${PHP_MAIL_CATCH_ALL:-2}

      ##
      ## Enable 127.0.0.1 Port-forwarding
      ##
      - FORWARD_PORTS_TO_LOCALHOST=80:httpd:80,443:httpd:443,3307:mysql:3307,5432:pgsql:5432,6379:redis:6379,11211:memcd:11211,27017:mongo:27017

      ##
      ## MySQL Backups
      ##
      - MYSQL_BACKUP_USER=root
      - MYSQL_BACKUP_PASS=${MYSQL_ROOT_PASSWORD}
      - MYSQL_BACKUP_HOST=mysql

    dns:
      - 172.16.238.100

    # MacOS and Windows have this by default, this hack also allows it for Linux
    extra_hosts:
      docker.for.lin.host.internal: 172.16.238.1
      docker.for.lin.localhost: 172.16.238.1

    networks:
      app_net:
        ipv4_address: 172.16.238.10

    volumes:
      # ---- Format: ----
      # HOST-DIRECTORY : DOCKER-DIRECTORY

      # Mount custom intranet
      - ${DEVILBOX_PATH}/.devilbox/www:/var/www/default:ro${MOUNT_OPTIONS}

      # Mount custom mass virtual hosting
      - ${HOST_PATH_HTTPD_DATADIR}:/shared/httpd:rw${MOUNT_OPTIONS}

      # Mount logs
      - ${DEVILBOX_PATH}/log/php-fpm-${PHP_SERVER}:/var/log/php:rw${MOUNT_OPTIONS}

      # Mount Mail directory
      - devilbox-mail:/var/mail:rw${MOUNT_OPTIONS}

      # Mount DB Backup directory
      - ${HOST_PATH_BACKUPDIR:-./backups}:/shared/backups:rw${MOUNT_OPTIONS}

      # Mount devilbox user-defined *.ini files in order
      # to overwrite the default PHP.ini configuration
      - ${DEVILBOX_PATH}/cfg/php-ini-${PHP_SERVER}:/etc/php-custom.d:ro${MOUNT_OPTIONS}

      # Mount devilbox user-defined PHP-FPM *.conf files in order
      # to overwrite the default PHP-FPM configuration
      - ${DEVILBOX_PATH}/cfg/php-fpm-${PHP_SERVER}:/etc/php-fpm-custom.d:ro${MOUNT_OPTIONS}

      # Mount devilbox user-defined *.so files in order
      # to load custom PHP modules
      - ${DEVILBOX_PATH}/mod/php-fpm-${PHP_SERVER}:/usr/lib64/php/custom-modules:ro${MOUNT_OPTIONS}

      # Mount devilbox user-defined PHP-FPM startup *.sh scripts
      - ${DEVILBOX_PATH}/cfg/php-startup-${PHP_SERVER}:/startup.1.d:rw${MOUNT_OPTIONS}
      - ${DEVILBOX_PATH}/autostart:/startup.2.d:rw${MOUNT_OPTIONS}

      # Mount devilbox user-defined bash config
      - ${DEVILBOX_PATH}/bash:/etc/bashrc-devilbox.d:rw${MOUNT_OPTIONS}

      # Mount devilbox user-defined supervisord config
      - ${DEVILBOX_PATH}/supervisor:/etc/supervisor/custom.d:rw${MOUNT_OPTIONS}

      # Certificate Authority public key
      - ${DEVILBOX_PATH}/ca:/ca:rw${MOUNT_OPTIONS}

      # Users SSH directory (read-only)
      - ${HOST_PATH_SSH_DIR}:/home/devilbox/.ssh:ro${MOUNT_OPTIONS}

    depends_on:
      - bind


  # ------------------------------------------------------------
  # Web Server
  # ------------------------------------------------------------
  httpd:
    image: devilbox/${HTTPD_SERVER}:0.40
    hostname: httpd

    environment:

      ##
      ## Debug/Logging
      ##
      - DEBUG_ENTRYPOINT=${DEBUG_COMPOSE_ENTRYPOINT}
      - DEBUG_RUNTIME=${DEBUG_COMPOSE_ENTRYPOINT}
      - DOCKER_LOGS

      ##
      ## Adjust timezone
      ##
      - TIMEZONE

      ##
      ## UserID and GroupID
      ##
      - NEW_UID
      - NEW_GID

      ##
      ## Nginx specific worker/connection settings
      ##
      - WORKER_PROCESSES=${HTTPD_NGINX_WORKER_PROCESSES:-auto}
      - WORKER_CONNECTIONS=${HTTPD_NGINX_WORKER_CONNECTIONS:-1024}

      ##
      ## Disable default vhost?
      ##
      - MAIN_VHOST_ENABLE=${DEVILBOX_UI_ENABLE}
      - MAIN_VHOST_STATUS_ENABLE=1
      - MAIN_VHOST_STATUS_ALIAS=/devilbox-httpd-status
      - MAIN_VHOST_SSL_TYPE=${HTTPD_VHOST_SSL_TYPE:-both}
      - MAIN_VHOST_SSL_GEN=1
      - MAIN_VHOST_SSL_CN=${DEVILBOX_UI_SSL_CN:-localhost}

      ##
      ## Enable Mass Vhosts
      ##
      - MASS_VHOST_ENABLE=1
      - MASS_VHOST_TLD=.${TLD_SUFFIX}
      - MASS_VHOST_DOCROOT=${HTTPD_DOCROOT_DIR}
      - MASS_VHOST_TPL=${HTTPD_TEMPLATE_DIR}
      - MASS_VHOST_SSL_TYPE=${HTTPD_VHOST_SSL_TYPE:-both}
      - MASS_VHOST_SSL_GEN=1

      ##
      ## PHP-FPM Remote Server
      ##
      - COMPAT=${PHP_SERVER}
      - PHP_FPM_ENABLE=1
      - PHP_FPM_SERVER_ADDR=172.16.238.10
      - PHP_FPM_SERVER_PORT=9000
      - PHP_FPM_TIMEOUT=${HTTPD_TIMEOUT_TO_PHP_FPM:-180}

    ports:
      # ---- Format: ----
      # [HOST-ADDR : ] HOST-PORT : DOCKER-PORT
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_HTTPD}:80"
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_HTTPD_SSL}:443"

    networks:
      app_net:
        ipv4_address: 172.16.238.11

    volumes:
      # ---- Format: ----
      # HOST-DIRECTORY : DOCKER-DIRECTORY

      # Mount custom intranet
      - ${DEVILBOX_PATH}/.devilbox/www:/var/www/default:ro${MOUNT_OPTIONS}

      # Mount custom mass virtual hosting
      - ${HOST_PATH_HTTPD_DATADIR}:/shared/httpd:rw${MOUNT_OPTIONS}

      # Mount custom web server config directory
      - ${DEVILBOX_PATH}/cfg/${HTTPD_SERVER}:/etc/httpd-custom.d:rw${MOUNT_OPTIONS}

      # Mount custom vhost-templates
      - ${DEVILBOX_PATH}/cfg/vhost-gen:/etc/vhost-gen.d:rw${MOUNT_OPTIONS}

      # Mount logs
      - ${DEVILBOX_PATH}/log/${HTTPD_SERVER}:/var/log/${HTTPD_SERVER}:rw${MOUNT_OPTIONS}

      # Certificate Authority public key
      - ${DEVILBOX_PATH}/ca:/ca:rw${MOUNT_OPTIONS}

    depends_on:
      - bind
      - php


  # ------------------------------------------------------------
  # MySQL Database
  # ------------------------------------------------------------
  mysql:
    image: devilbox/mysql:${MYSQL_SERVER}-0.8
    hostname: mysql

    environment:
      - MYSQL_ROOT_PASSWORD
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes

    ports:
      # [local-machine:]local-port:docker-port
      #- "${LOCAL_LISTEN_ADDR}${HOST_PORT_MYSQL}:3306"
      - "3307:3307"

    networks:
      app_net:
        ipv4_address: 172.16.238.12

    volumes:
      # ---- Format: ----
      # HOST-DIRECTORY : DOCKER-DIRECTORY

      # Mount devilbox user-defined cnf files in order
      # to overwrite the MySQL server configuration
      - ${DEVILBOX_PATH}/.devilbox/cfg/mysql.cnf:/etc/mysql/conf.d/devilbox.cnf:ro${MOUNT_OPTIONS}
      - ${DEVILBOX_PATH}/cfg/${MYSQL_SERVER}:/etc/mysql/docker-default.d:ro${MOUNT_OPTIONS}

      # Mount MySQL Data directory
      - devilbox-${MYSQL_SERVER}:/var/lib/mysql:rw${MOUNT_OPTIONS}

    depends_on:
      - bind
      - php
      - httpd


  # ------------------------------------------------------------
  # PostgreSQL
  # ------------------------------------------------------------
  pgsql:
    image: postgres:${PGSQL_SERVER}
    hostname: pgsql

    environment:

      - POSTGRES_USER=${PGSQL_ROOT_USER}
      - POSTGRES_PASSWORD=${PGSQL_ROOT_PASSWORD}
      - POSTGRES_HOST_AUTH_METHOD=${PGSQL_HOST_AUTH_METHOD:-trust}
      - PGDATA=/var/lib/postgresql/data/pgdata

    ports:
      # [local-machine:]local-port:docker-port
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_PGSQL}:5432"

    networks:
      app_net:
        ipv4_address: 172.16.238.13

    volumes:
      # ---- Format: ----
      # HOST-DIRECTORY : DOCKER-DIRECTORY

      # Mount PostgreSQL Data directory
      - devilbox-pgsql-${PGSQL_SERVER}:/var/lib/postgresql/data/pgdata:rw${MOUNT_OPTIONS}

    depends_on:
      - bind
      - php
      - httpd


  # ------------------------------------------------------------
  # Redis
  # ------------------------------------------------------------
  redis:
    image: redis:${REDIS_SERVER}
    hostname: redis

    # Apply custom arguments to redis startup
    command: redis-server ${REDIS_ARGS:- }
    environment:
      - REDIS_ARGS=${REDIS_ARGS:- }

    ports:
      # [local-machine:]local-port:docker-port
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_REDIS}:6379"

    networks:
      app_net:
        ipv4_address: 172.16.238.14

    depends_on:
      - bind
      - php
      - httpd


  # ------------------------------------------------------------
  # Memcached
  # ------------------------------------------------------------
  memcd:
    image: memcached:${MEMCD_SERVER}
    hostname: memcd

    ports:
      # [local-machine:]local-port:docker-port
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_MEMCD}:11211"

    networks:
      app_net:
        ipv4_address: 172.16.238.15

    depends_on:
      - bind
      - php
      - httpd


  # ------------------------------------------------------------
  # MongoDB
  # ------------------------------------------------------------
  mongo:
    image: mongo:${MONGO_SERVER}
    hostname: mongo

    ports:
      # [local-machine:]local-port:docker-port
      - "${LOCAL_LISTEN_ADDR}${HOST_PORT_MONGO}:27017"

    networks:
      app_net:
        ipv4_address: 172.16.238.16

    volumes:
      # ---- Format: ----
      # HOST-DIRECTORY : DOCKER-DIRECTORY

      # Mount MongoDB Data directory
      - devilbox-mongo-${MONGO_SERVER}:/data/db:rw${MOUNT_OPTIONS}

    depends_on:
      - bind
      - php
      - httpd


################################################################################
# NETWORK
################################################################################
networks:
  app_net:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
        - subnet: 172.16.238.0/24
          gateway: 172.16.238.1


################################################################################
# VOLUMES
################################################################################
volumes:
  # ------------------------------------------------------------
  # Misc
  # ------------------------------------------------------------
  devilbox-mail:

  # ------------------------------------------------------------
  # MySQL
  # ------------------------------------------------------------
  devilbox-mysql-5.5:
  devilbox-mysql-5.6:
  devilbox-mysql-5.7:
  devilbox-mysql-8.0:
  devilbox-mariadb-5.5:
  devilbox-mariadb-10.0:
  devilbox-mariadb-10.1:
  devilbox-mariadb-10.2:
  devilbox-mariadb-10.3:
  devilbox-mariadb-10.4:
  devilbox-mariadb-10.5:
  devilbox-mariadb-10.6:
  devilbox-mariadb-10.7:
  devilbox-percona-5.5:
  devilbox-percona-5.6:
  devilbox-percona-5.7:
  devilbox-percona-8.0:

  # ------------------------------------------------------------
  # Postgres
  # ------------------------------------------------------------
...

php-fpm.error (log file from devilbox/log/php-fpm-7.4/)
[02-Mar-2022 17:44:39 GMT] PHP Warning:  mysqli::__construct(): Error while reading greeting packet. PID=2117 in /shared/httpd/hostdb/htdocs/index.php on line 8
[02-Mar-2022 17:44:39 GMT] PHP Warning:  mysqli::__construct(): (HY000/2006): MySQL server has gone away in /shared/httpd/hostdb/htdocs/index.php on line 8

Can someone take a look at my setting where I am getting wrong, please?

lendoo

Hi Everyone,

At least I found the solution:
In the docker-compse.yml file I needed to add another extra_hosts to the php service:

services:
    php:
        extra_hosts:
            host.docker.internal: host-gateway

Everything else is the default settings! No need any other setup.
In php file:

$servername = "host.docker.internal:3307";

Or any other port number you want to use (if your db-server runs on 3306, then you can omit the port number).

2 Likes