Page MenuHomePhabricator

MediaWiki Won't Connect to SQLite in Docker
Open, Needs TriagePublicBUG REPORT


Not sure if this is a bug report or a request for help.

List of steps to reproduce:

Folder structure:

     generated/ (empty)
     data/      (empty)

./docker-compose.yml contains:

version: "3.8"

    build: wiki/.
      - "80:80"
    restart: on-failure
      - type: bind
        source: ./wiki/data
        target: /var/www/data

wiki/Dockerfile contains:

FROM mediawiki:latest

RUN apt update
RUN apt install sqlite3

COPY ./generated/ /var/www/html

(The last command copies ./generated/LocalSettings.php into the image, once it's there)

What happens?

Navigate to http://localhost:80/ and I am prompted to "complete the installation", so I do so, with the following settings:

  • Next Page: Languages: english / english
  • Next Page: Environmental checks pass.
  • Next Page: database: SQLite, SQLite data directory: /var/www/data, Database name: my_wiki
  • Next Page: Name of my Wiki: My Wiki, username, password, email, etc..., Ask More Questions...
  • Next Page: Open Wiki, No license footer, Disable Outbound Email, leave three skins, add three editors, Continue...
  • Next Page: 'Continue' to start installation

Installation Fails:

 * Including extensions... done
 * Setting up database...

**Warning**: file_put_contents(/var/www/data/.htaccess): failed to open stream: Permission denied in **/var/www/html/includes/installer/SqliteInstaller.php** on **line 184**

**Warning**: file_put_contents(/var/www/data/my_wiki.sqlite): failed to open stream: Permission denied in **/var/www/html/includes/installer/SqliteInstaller.php** on **line 327**

**Warning**: file_put_contents(/var/www/data/wikicache.sqlite): failed to open stream: Permission denied in **/var/www/html/includes/installer/SqliteInstaller.php** on **line 327**

**Warning**: file_put_contents(/var/www/data/my_wiki_l10n_cache.sqlite): failed to open stream: Permission denied in **/var/www/html/includes/installer/SqliteInstaller.php** on **line 327**

**Warning**: file_put_contents(/var/www/data/my_wiki_jobqueue.sqlite): failed to open stream: Permission denied in **/var/www/html/includes/installer/SqliteInstaller.php** on **line 327**

Then in red:

Could not create database file ``/var/www/data/my_wiki.sqlite``.
Could not create database file ``/var/www/data/wikicache.sqlite``.
Could not create database file ``/var/www/data/my_wiki_l10n_cache.sqlite``.
Could not create database file ``/var/www/data/my_wiki_jobqueue.sqlite``.

What I've Tried:

Check accessibility of /var/www/data:

I've checked that the bind mount is working correctly:

docker exec wiki_container -it /bin/bash
cd /var/www/data

And then cat something >test.txt places test.txt on the host drive, so the folder is mounted and writeable.

SQLite Test:

I had a SQLite database for a MediaWiki created in a different environment, so I copied it into the wiki/data folder to be bound into the container, and copied the LocalSettings.php file into wiki/generated, rebuilt, and ran the compose file. When running sqlite3 from the running container's command line, I was able to connect to the database at /var/www/data/my_wiki.sqlite and list tables, etc., but MediaWiki was not able to find it, and reported 'Site unavailable... (Cannot access database)

Where do I go?

So, the data folder is attached and writeable, SQLite is installed and working with it; I'm not sure where else to look...

Event Timeline

gebbber updated the task description. (Show Details)

I suspect that the permissions on the directory, or specifically the sqlite files will be incorrect. for whatever user you are trying to write them as.

How are you running install.php

If you check who owns the directory with ls what does it say?

If you are using MediaWiki-Docker as a development environment it might be worth looking at

Because this issue is a couple of years old, with no follow up about the question of whether the reporter is using MediaWiki-Docker, it's hard to surmise if I'm having the same problem.

The error messages I got were not during installation, but after completing all the prescribed steps in and visiting localhost:8080 for the first time.

Sorry! This site is experiencing technical difficulties.

Try waiting a few minutes and reloading.

(Cannot access the database: Cannot access the database: No database connection (unknown))


#0 /var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancer.php(972): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()
#1 /var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancer.php(944): Wikimedia\Rdbms\LoadBalancer->getServerConnection()
#2 /var/www/html/w/includes/libs/rdbms/database/DBConnRef.php(95): Wikimedia\Rdbms\LoadBalancer->getConnectionInternal()
#3 /var/www/html/w/includes/libs/rdbms/database/DBConnRef.php(101): Wikimedia\Rdbms\DBConnRef->ensureConnection()
#4 /var/www/html/w/includes/libs/rdbms/database/DBConnRef.php(344): Wikimedia\Rdbms\DBConnRef->__call()
#5 /var/www/html/w/includes/page/WikiPage.php(408): Wikimedia\Rdbms\DBConnRef->selectRow()
#6 /var/www/html/w/includes/page/WikiPage.php(430): WikiPage->pageData()
#7 /var/www/html/w/includes/page/WikiPage.php(470): WikiPage->pageDataFromTitle()
#8 /var/www/html/w/includes/page/WikiPage.php(587): WikiPage->loadPageData()
#9 /var/www/html/w/includes/page/WikiPage.php(661): WikiPage->exists()
#10 /var/www/html/w/includes/page/WikiPage.php(296): WikiPage->getContentModel()
#11 /var/www/html/w/includes/MediaWiki.php(437): WikiPage->getContentHandler()
#12 /var/www/html/w/includes/MediaWiki.php(320): MediaWiki->initializeArticle()
#13 /var/www/html/w/includes/MediaWiki.php(904): MediaWiki->performRequest()
#14 /var/www/html/w/includes/MediaWiki.php(562): MediaWiki->main()
#15 /var/www/html/w/index.php(50): MediaWiki->run()
#16 /var/www/html/w/index.php(46): wfIndexMain()
#17 {main}

My one clue was that the php-fpm child processes (which I presume is the web server) run within the Docker container as the nobody user. That gave me the idea to follow the advice for "Windows users" in this section of

docker compose exec mediawiki chmod -R o+rwx cache/sqlite

….which solved the problem for me.

My question is, does this warrant a bug report to amend or the associated Docker installation script(s) to just apply that fix out of the box? Making something world-writable feels kind of dirty, but maybe it's okay inside a Docker image…