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:
Doctrine\DBAL\Exception:
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/XXX/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.
This is cross-posted from serverfault: