NathanVaughn / webtrees-docker

Up-to-date Docker image for webtrees with all the bells and whistles.
https://hub.docker.com/r/nathanvaughn/webtrees
MIT License
59 stars 15 forks source link

SQLSTATE[HY000] [2002] No such file or directory (SQL: CREATE DATABASE IF NOT EXISTS #116

Closed J0han3s closed 5 months ago

J0han3s commented 1 year ago

Hi ,

Please can you help. I have launched webtrees-docker using docker compose onto my server. I changed the host port from 80, as i already have 80 taken. However, when i try to go through the Webtrees setup wizard, i cannot get past the first page.

I get the following error: SQLSTATE[HY000] [2002] No such file or directory (SQL: CREATE DATABASE IF NOT EXISTSwebtreesCOLLATE utf8_unicode_ci)

Here is the log from the app

[NV_INIT] PRETTY_URLS found in environment variables [NV_INIT] HTTPS found in environment variables [NV_INIT] HTTPS_REDIRECT found in environment variables [NV_INIT] SSL_CERT_FILE NOT found in environment variables, using default: /certs/webtrees.crt [NV_INIT] SSL_CERT_KEY_FILE NOT found in environment variables, using default: /certs/webtrees.key [NV_INIT] BASE_URL found in environment variables [NV_INIT] LANG found in environment variables [NV_INIT] DB_TYPE found in environment variables [NV_INIT] DB_HOST found in environment variables [NV_INIT] DB_PORT found in environment variables [NV_INIT] DB_USER found in environment variables [NV_INIT] DB_PASS found in environment variables [NV_INIT] DB_NAME found in environment variables [NV_INIT] DB_PREFIX found in environment variables [NV_INIT] WT_USER found in environment variables [NV_INIT] WT_NAME found in environment variables [NV_INIT] WT_PASS found in environment variables [NV_INIT] WT_EMAIL found in environment variables [NV_INIT] DB_KEY NOT found in environment variables, using default: None [NV_INIT] DB_CERT NOT found in environment variables, using default: None [NV_INIT] DB_CA NOT found in environment variables, using default: None [NV_INIT] DB_VERIFY NOT found in environment variables, using default: None [NV_INIT] PHP_MEMORY_LIMIT NOT found in environment variables, using default: 1024M [NV_INIT] PHP_MAX_EXECUTION_TIME NOT found in environment variables, using default: 90 [NV_INIT] PHP_POST_MAX_SIZE NOT found in environment variables, using default: 50M [NV_INIT] PHP_UPLOAD_MAX_FILE_SIZE NOT found in environment variables, using default: 50M [NV_INIT] Setting up folder permissions for uploads [NV_INIT] Updating php.ini [NV_INIT] Creating php.ini [NV_INIT] Setting value for memory_limit in php.ini [NV_INIT] Setting value for max_execution_time in php.ini [NV_INIT] Setting value for post_max_size in php.ini [NV_INIT] Setting value for upload_max_filesize in php.ini [NV_INIT] Attempting to automate setup wizard [NV_INIT] Automating setup wizard [NV_INIT] Starting Apache in background [NV_INIT] Disabling site webtrees-redir Site webtrees-redir already disabled [NV_INIT] Disabling site webtrees-ssl Site webtrees-ssl already disabled [NV_INIT] Enabling site webtrees Enabling site webtrees. To activate the new configuration, you need to run: service apache2 reload [NV_INIT] Waiting for MySQL server to be ready AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message [Sat Jan 14 15:04:55.047674 2023] [mpm_prefork:notice] [pid 27] AH00163: Apache/2.4.54 (Debian) PHP/8.1.13 OpenSSL/1.1.1n configured -- resuming normal operations [Sat Jan 14 15:04:55.048058 2023] [core:notice] [pid 27] AH00094: Command line: 'apache2 -D FOREGROUND' [NV_INIT] Waiting for MySQL server to be ready [NV_INIT] Waiting for MySQL server to be ready [NV_INIT] Sending setup wizard request webtrees:80 127.0.0.1 - - [14/Jan/2023:15:04:57 +0000] "POST / HTTP/1.1" 200 3840 "-" "Python-urllib/3.9" [NV_INIT] Stopping Apache [NV_INIT] Updating config file [NV_INIT] Config file not found at /var/www/webtrees/data/config.ini.php. Nothing to update. [NV_INIT] Configuring HTTPS [NV_INIT] Removing HTTPS [NV_INIT] Disabling site webtrees-redir [Sat Jan 14 15:04:58.052091 2023] [mpm_prefork:notice] [pid 27] AH00169: caught SIGTERM, shutting down Site webtrees-redir already disabled [NV_INIT] Disabling site webtrees-ssl Site webtrees-ssl already disabled [NV_INIT] Enabling site webtrees Site webtrees already enabled [NV_INIT] Setting up folder permissions for uploads [NV_INIT] Starting Apache AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message [Sat Jan 14 15:04:58.319851 2023] [mpm_prefork:notice] [pid 64] AH00163: Apache/2.4.54 (Debian) PHP/8.1.13 OpenSSL/1.1.1n configured -- resuming normal operations [Sat Jan 14 15:04:58.320074 2023] [core:notice] [pid 64] AH00094: Command line: 'apache2 -D FOREGROUND' webtrees:80 127.0.0.1 - - [14/Jan/2023:15:05:24 +0000] "GET / HTTP/1.1" 200 6448 "-" "curl/7.74.0" webtrees:80 127.0.0.1 - - [14/Jan/2023:15:05:55 +0000] "GET / HTTP/1.1" 200 6448 "-" "curl/7.74.0" webtrees:80 127.0.0.1 - - [14/Jan/2023:15:06:25 +0000] "GET / HTTP/1.1" 200 6448 "-" "curl/7.74.0"

Here is the log from the db

2023-01-14 15:04:52+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started. 2023-01-14 15:04:56+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2023-01-14 15:04:56+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started. 2023-01-14 15:04:56+00:00 [Note] [Entrypoint]: MariaDB upgrade information missing, assuming required 2023-01-14 15:04:56+00:00 [Note] [Entrypoint]: MariaDB upgrade (mariadb-upgrade) required, but skipped due to $MARIADB_AUTO_UPGRADE setting 2023-01-14 15:04:56 0 [Note] mariadbd (server 10.10.2-MariaDB-1:10.10.2+maria~ubu2204) starting as process 1 ... 2023-01-14 15:04:56 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2023-01-14 15:04:56 0 [Note] InnoDB: Number of transaction pools: 1 2023-01-14 15:04:56 0 [Note] InnoDB: Using generic crc32 instructions 2023-01-14 15:04:56 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts) 2023-01-14 15:04:56 0 [Warning] mariadbd: io_uring_queue_init() failed with ENOSYS: check seccomp filters, and the kernel version (newer than 5.1 required) 2023-01-14 15:04:56 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF 2023-01-14 15:04:56 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB 2023-01-14 15:04:56 0 [Note] InnoDB: Completed initialization of buffer pool 2023-01-14 15:04:57 0 [Note] InnoDB: File system buffers for log disabled (block size=4096 bytes) 2023-01-14 15:04:57 0 [Note] InnoDB: 128 rollback segments are active. 2023-01-14 15:04:57 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ... 2023-01-14 15:04:57 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB. 2023-01-14 15:04:57 0 [Note] InnoDB: log sequence number 46806; transaction id 14 2023-01-14 15:04:57 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2023-01-14 15:04:57 0 [Note] Plugin 'FEEDBACK' is disabled. 2023-01-14 15:04:57 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work. 2023-01-14 15:04:57 0 [Note] Server socket created on IP: '0.0.0.0'. 2023-01-14 15:04:57 0 [Note] Server socket created on IP: '::'. 2023-01-14 15:04:57 0 [Note] InnoDB: Buffer pool(s) load completed at 230114 15:04:57 2023-01-14 15:04:57 0 [Warning] 'user' entry 'root@36059ce60517' ignored in --skip-name-resolve mode. 2023-01-14 15:04:57 0 [Warning] 'proxies_priv' entry '@% root@36059ce60517' ignored in --skip-name-resolve mode. 2023-01-14 15:04:57 0 [Note] mariadbd: ready for connections. Version: '10.10.2-MariaDB-1:10.10.2+maria~ubu2204' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution 2023-01-14 15:04:57 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'unauthenticated' host: '172.19.0.3' (This connection closed normally without authentication) 2023-01-14 15:04:57 4 [Warning] Aborted connection 4 to db: 'unconnected' user: 'unauthenticated' host: '172.19.0.3' (This connection closed normally without authentication)

NathanVaughn commented 1 year ago

First off, from your log, it looks like the webtrees container was able to automatically run through the setup wizard. I would delete any volumes you have, and restart everything.

Based on [Warning] Aborted connection 3 to db: 'unconnected' user: 'unauthenticated' host: '172.19.0.3' (This connection closed normally without authentication) I think you have some problem with how your MariaDB container is setup.

While debugging this, I did find an issue that would cause the container to restart once on start up when it shouldn't. That has been fixed.

Regardless, this compose file worked fine for me:

version: "3"

services:
  app:
    depends_on:
      - db
    environment:
      PRETTY_URLS: "1"
      HTTPS: "0"
      HTTPS_REDIRECT: "0"
      LANG: "en-US"
      BASE_URL: "http://localhost:5000"
      DB_TYPE: "mysql"
      DB_HOST: "db"
      DB_PORT: "3306"
      DB_USER: "webtrees"
      DB_PASS: "badpassword"
      DB_NAME: "webtrees"
      DB_PREFIX: "wt_"
      WT_USER: "username"
      WT_NAME: "Full Name"
      WT_PASS: "mybadpassword"
      WT_EMAIL: "me@example.com"
    image: test:latest
    ports:
      - 5000:80
    restart: unless-stopped
    volumes:
      - app_data:/var/www/webtrees/data/
      - app_media:/var/www/webtrees/media/

  db:
    environment:
      MARIADB_DATABASE: "webtrees"
      MARIADB_USER: "webtrees"
      MARIADB_ROOT_PASSWORD: "badpassword"
      MARIADB_PASSWORD: "badpassword"
    image: docker.io/library/mariadb:latest
    restart: unless-stopped
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:
    driver: local
  app_data:
    driver: local
  app_media:
    driver: local
Eschguy commented 5 months ago

Having the same issue

NathanVaughn commented 5 months ago

Sorry, I was on a trip. Could you post your log and anonymized docker compose file?

Eschguy commented 5 months ago

Compose

version: "3"

services:
  app:
    container_name: webtrees
    depends_on:
      - db
    environment:
      PRETTY_URLS: "1"
      # HTTPS: "1"
      # HTTPS_REDIRECT: "1"
      LANG: "en-US"
      BASE_URL: "http://localhost"
      # DB_TYPE: "mysql"
      # DB_HOST: "db"
      # DB_PORT: "3306"
      # DB_USER: "webtrees"
      # DB_PASS: "badpassword"
      # DB_NAME: "webtrees"
      # DB_PREFIX: "wt_"
      # WT_USER: "username"
      # WT_NAME: "Full Name"
      # WT_PASS: "mybadpassword"
      # WT_EMAIL: "me@example.com"
    image: ghcr.io/nathanvaughn/webtrees:latest
    #build: .
    ports:
      - 9180:80
      - 9143:443
    restart: unless-stopped
    volumes:
      - app_data:/var/www/webtrees/data/
      - app_media:/var/www/webtrees/media/

  db:
    container_name: webtrees-db
    environment:
      MYSQL_DATABASE: "webtrees"
      MYSQL_USER: "webtrees"
      MYSQL_ROOT_PASSWORD: "badpassword"
      MYSQL_PASSWORD: "badpassword"
    image: mariadb:latest
    restart: unless-stopped
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:
    driver: local
  app_data:
    driver: local
  app_media:
    driver: local

Logs

[NV_INIT] SSL NOT found in environment variables, using default: None
[NV_INIT] HTTPS NOT found in environment variables, using default: None
[NV_INIT] SSL_REDIRECT NOT found in environment variables, using default: None
[NV_INIT] HTTPS_REDIRECT NOT found in environment variables, using default: None
[NV_INIT] SSL_CERT_FILE NOT found in environment variables, using default: /certs/webtrees.crt
[NV_INIT] SSL_CERT_KEY_FILE NOT found in environment variables, using default: /certs/webtrees.key
[NV_INIT] BASE_URL found in environment variables
[NV_INIT] LANG found in environment variables
[NV_INIT] DB_TYPE NOT found in environment variables, using default: mysql
[NV_INIT] DB_HOST NOT found in environment variables, using default: None
[NV_INIT] DB_PORT NOT found in environment variables, using default: 3306
[NV_INIT] MYSQL_USER NOT found in environment variables, using default: None
[NV_INIT] MARIADB_USER NOT found in environment variables, using default: None
[NV_INIT] POSTGRES_USER NOT found in environment variables, using default: None
[NV_INIT] DB_USER NOT found in environment variables, using default: webtrees
[NV_INIT] MYSQL_PASSWORD NOT found in environment variables, using default: None
[NV_INIT] MARIADB_PASSWORD NOT found in environment variables, using default: None
[NV_INIT] POSTGRES_PASSWORD NOT found in environment variables, using default: None
[NV_INIT] DB_PASS NOT found in environment variables, using default: None
[NV_INIT] MYSQL_DATABASE NOT found in environment variables, using default: None
[NV_INIT] MARIADB_DATABASE NOT found in environment variables, using default: None
[NV_INIT] POSTGRES_DB NOT found in environment variables, using default: None
[NV_INIT] DB_NAME NOT found in environment variables, using default: webtrees
[NV_INIT] DB_PREFIX NOT found in environment variables, using default: wt_
[NV_INIT] WT_USER NOT found in environment variables, using default: None
[NV_INIT] WT_NAME NOT found in environment variables, using default: None
[NV_INIT] WT_PASS NOT found in environment variables, using default: None
[NV_INIT] WT_EMAIL NOT found in environment variables, using default: None
[NV_INIT] DB_KEY NOT found in environment variables, using default: None
[NV_INIT] DB_CERT NOT found in environment variables, using default: None
[NV_INIT] DB_CA NOT found in environment variables, using default: None
[NV_INIT] DB_VERIFY NOT found in environment variables, using default: None
[NV_INIT] PHP_MEMORY_LIMIT NOT found in environment variables, using default: 1024M
[NV_INIT] PHP_MAX_EXECUTION_TIME NOT found in environment variables, using default: 90
[NV_INIT] PHP_POST_MAX_SIZE NOT found in environment variables, using default: 50M
[NV_INIT] PHP_UPLOAD_MAX_FILE_SIZE NOT found in environment variables, using default: 50M
[NV_INIT] PUID NOT found in environment variables, using default: 33
[NV_INIT] PGID NOT found in environment variables, using default: 33
[NV_INIT] Setting up folder permissions for uploads
usermod: no changes
[NV_INIT] Updating php.ini
[NV_INIT] Creating php.ini
[NV_INIT] Setting value for memory_limit in php.ini
[NV_INIT] Setting value for max_execution_time in php.ini
[NV_INIT] Setting value for post_max_size in php.ini
[NV_INIT] Setting value for upload_max_filesize in php.ini
[NV_INIT] Attempting to automate setup wizard
[NV_INIT] WARNING: Not all database variables are set
[NV_INIT] Updating config file
[NV_INIT] Config file not found at /var/www/webtrees/data/config.ini.php. Nothing to update.
[NV_INIT] Configuring HTTPS
[NV_INIT] Removing HTTPS
[NV_INIT] Disabling site webtrees-redir
Site webtrees-redir already disabled
[NV_INIT] Disabling site webtrees-ssl
Site webtrees-ssl already disabled
[NV_INIT] Enabling site webtrees
Enabling site webtrees.
To activate the new configuration, you need to run:
  service apache2 reload
[NV_INIT] Setting up folder permissions for uploads
usermod: no changes
[NV_INIT] Starting Apache
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.30.0.3. Set the 'ServerName' directive globally to suppress this message
[Tue Jan 30 19:59:42.792704 2024] [mpm_prefork:notice] [pid 39] AH00163: Apache/2.4.57 (Debian) PHP/8.1.25 OpenSSL/3.0.11 configured -- resuming normal operations
[Tue Jan 30 19:59:42.798325 2024] [core:notice] [pid 39] AH00094: Command line: 'apache2 -D FOREGROUND'
[Tue Jan 30 19:59:42.792704 2024] [mpm_prefork:notice] [pid 39] AH00163: Apache/2.4.57 (Debian) PHP/8.1.25 OpenSSL/3.0.11 configured -- resuming normal operations
[Tue Jan 30 19:59:42.798325 2024] [core:notice] [pid 39] AH00094: Command line: 'apache2 -D FOREGROUND'
webtrees:80 127.0.0.1 - - [30/Jan/2024:20:00:12 +0000] "GET / HTTP/1.1" 200 6448 "-" "curl/7.88.1"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:30 +0000] "GET / HTTP/1.1" 200 1670 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:31 +0000] "GET /favicon.ico HTTP/1.1" 200 15333 "https://DOMAIN.COM" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:33 +0000] "POST / HTTP/1.1" 200 1382 "https://DOMAIN.COM" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:36 +0000] "POST / HTTP/1.1" 200 1266 "https://DOMAIN.COM" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:39 +0000] "POST / HTTP/1.1" 200 1700 "https://DOMAIN.COM" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
webtrees:80 127.0.0.1 - - [30/Jan/2024:20:00:42 +0000] "GET / HTTP/1.1" 200 6448 "-" "curl/7.88.1"
webtrees:80 172.30.0.1 - - [30/Jan/2024:20:00:55 +0000] "POST / HTTP/1.1" 200 1827 "https://DOMAIN.COM/" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
NathanVaughn commented 5 months ago

Again, sorry for the delay, I've been feeling a bit sick. I tried your compose file, and started to manually run the setup wizard. Are you using the correct host for the database? For example, using localhost gets the error in the title

image

Fixing this to db works as expected. Afterwards, I was able to complete the setup wizard.

Eschguy commented 5 months ago

Fixing this to db works as expected

Yep, that was the issue. Strange. Thanks for the follow-up, hope you're feeling better.

NathanVaughn commented 5 months ago

Thanks. So, this is because Docker containers only allow inbound connections from other containers in the same docker compose stack by default. To allow connections from outside sources, you need to map ports to the host. The other problem is how localhost works in docker. localhost will refer to the container itself, not the host it is running on.

Put together, when you set the database as localhost, it's trying to connect on 127.0.0.1, which is the container running webtrees, and there is no database running, so it doesn't work. When you set it to db, this is referencing the container's IP address in the docker compose stack, and because the web server and database are in the same stack, this is allowed. Your other option is to run it on a different machine or something like I do. In my case, I put in mariadb.service.consul, and because I've mapped port 3306 to the host of that container, that also works.