Nextcloud migration to docker container and MySQL/MariaDB ‘Access denied’

I’m attempting to migrate my Nextcloud 29 instance to a new server. Previously, it was running on a bare LAMP stack on Ubuntu 18.04, with PHP 8.2 and MySQL 8. The new setup uses Docker with this .yml file:

version: '3'
services:
  php-apache:
    build:
      context: ./php-apache
    restart: unless-stopped
    depends_on:
      - sql-db
    ports:
      - "${SITE_PORT}:80"
    volumes:
      - ./html:/var/www/html:rw
      - /media/cloud/data/nextcloud-data:/var/www/nextcloud-data:rw
      - ./htmllogs:/var/log/apache2:rw
      - ./php-fpm-www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
    links:
      - sql-db
    environment:
      - "MYSQL_USER: ${MYSQL_USER}"
      - "MYSQL_PASSWORD: ${MYSQL_PASSWORD}"
      - "MYSQL_DATABASE: ${MYSQL_DATABASE}"
      - "LAMP_UID=${LAMP_UID}"
      - "LAMP_GID=${LAMP_GID}"
    networks:
      - www-network

  sql-db:
    image: "mysql:8.4"
    restart: unless-stopped
    ports:
      - ${SQL_PORT}:3306
    volumes:
      - ./sql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_USER: "${MYSQL_USER}"
      MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
      MYSQL_DATABASE: "${MYSQL_DATABASE}"
    networks:
      - www-network

networks:
  www-network:
    name: www-network
    driver: bridge

and the Dockerfile for the php container context is:

FROM php:8.2-apache

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && 
    install-php-extensions pdo pdo_mysql gd imagick zip intl xdebug && 
    a2enmod rewrite

I’ve restored the db from my backup into the new container, restored the nextcloud files and data, adjusted my config.php as following:

<?php
$CONFIG = array (
  'instanceid' => 'XXX',
  'passwordsalt' => 'XXX',
  'secret' => 'XXX',
  'trusted_domains' => 
  array (
    0 => 'XXX',
  ),
  'trusted_proxies' => 
  array (
    0 => 'XXX',
  ),
  'datadirectory' => '/var/www/nextcloud-data',
  'overwrite.cli.url' => 'XXX',
  'dbtype' => 'mysql',
  'dbname' => 'nextcloud',
  'dbhost' => 'sql-db',
  'dbport' => '3306',
  'dbuser' => 'nc',
  'dbpassword' => 'XXX',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'installed' => true,
  'maintenance_window_start' => 5,
  'app_install_overwrite' => 
  array (
    0 => 'occweb',
  ),
  'default_phone_region' => 'US',
  'htaccess.RewriteBase' => '/',
  'maintenance' => true,
  'theme' => '',
  'loglevel' => 0,
  'defaultapp' => '',
);

Now when I either navigate to the server in a browser or run php occ from within the container, I get this:

An unhandled exception has been thrown:
DoctrineDBALException:
    Failed to connect to the database: An exception occurred in the driver:
    SQLSTATE[HY000] [1045] Access denied for user 'nc'@'localhost' (using password: YES)
    in /home/www-docker/sites/cloud.carpenter.family/lib/private/DB/Connection.php:163

(newlines and indent added for readability)

My troubleshooting steps:

I wrote this test.php file that succeeds, whether browsed to or invoked from within the container, with values pasted straight out of the nextcloud config file:

<?php

try{
    $dbh = new pdo( 'mysql:host=sql-db:3306;dbname=nextcloud',
        'nc',
        'XXX',
        array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    $sql = "select uid from oc_users where uid='admin';";
    foreach ($dbh->query($sql) as $row) {
        echo json_encode($row)."n";
    }
    die(json_encode(array('outcome' => true)));
}
catch(PDOException $ex){
    die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
}

I have also swapped (and reloaded) the SQL database between both MySQL and MariaDB.

I have even gone so far as to attempt to restore this to a bare LAMP stack on Ubuntu 24.04, all with this same outcome, Access denied from nextcloud, but success from my test.php, so it really doesn’t seem like my docker setup is the issue.

Is there something persisting perhaps in my nextcloud directory that is overriding my credentials? Why would a test script in the exact same context succeed where nextcloud does not?

Everything about this screams “duh, bad credentials”, but I’m just not seeing it.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật