I cannot for the life of me connect to mysql

I’ve been trying to connect the app to the mysql database for hours with no luck, I’m really starting to hate docker…

I’m trying to setup a project that someone else built (doesn’t work here anymore) and he used docker. I managed to actually get it working using xampp at first, but it was having issues with the PHP version and after downgrading it kept having PHP problems that I didn’t manage to resolve. So I know that the database can connect and isn’t an issue with the code.

Here’s the docker-compose file:

version: "3.9"

services:
  php:
    build: .
    ports:
      - 80:80
    volumes:
      - ./src/app:/var/www/html
    environment:
      - ALLOW_OVERRIDE=true

  db:
    image: mysql:5.6
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: app_rs
    volumes:
      - dbdata:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin
    ports:
      - 8081:80
    environment:
      - PMA_ARBITRARY=1

volumes:
  dbdata:

Here’s the db config file:

$manager->setConfiguration(array(
  'dsn' => 'mysql:host=db;port=3306;dbname=app_rs',
  'user' => 'root',
  'password' => 'password',
  'settings' =>
  array(
    'charset' => 'utf8',
    'queries' =>
    array(),
  ),
  'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper',
  'model_paths' =>
  array(
    0 => 'src',
    1 => 'vendor',
  ),
));

Here is the Dockerfile:

FROM php:5.6-apache

# RUN apt-get update && apt-get install -y \
#         libfreetype6-dev \
#         libjpeg62-turbo-dev \
#         libpng-dev \
#         curl \
#         libcurl4-openssl-dev \
#         openssl \
#    && docker-php-ext-configure gd --with-freetype --with-jpeg \
#     && docker-php-ext-install -j$(nproc) gd

# RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql
# RUN docker-php-ext-install curl && docker-php-ext-enable curl
RUN a2enmod rewrite

#COPY ./php.ini "$PHP_INI_DIR/php.ini"
ADD ./src /var/www/html

The commented out stuff I had to comment out because it wouldn’t start otherwise. I installed them separately, but I’ll add them in case they might be a cause. I would also like to note that the 5.6-apache image is extremely limited so I can’t install any other useful tools like nano, ip, mysql, or anything like that.

I’ve tried every host setting I came across and nothing has worked. It’s incredibly frustrating how much work docker is to set up every single time, especially getting the database connected (sorry, I’m just a little extremely frustrated).
I’m on Windows 10.

I’m really at a loss on getting this working.

I finally managed to fix it with the help of ChatGPT 4, which recommended uncommenting this line:

# RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql

in the Dockerfile which finally got it working correctly.

1 Like