CompleteNoobs Local Wiki In Docker

From CompleteNoobs
Revision as of 22:59, 16 February 2025 by AwesomO (talk | contribs) (Created page with " ==Starting Environment== * '''Hardware''': HP EliteDesk 800 G1 * '''Operating System''': Ubuntu-Mate 24.04 * '''Installation Type''': Fresh Install * '''Initial Setup Post-Install''': Package Update: <code>sudo apt update && sudo apt upgrade -y</code> * '''Additional Software''': Installed just to record screen for this tut and not needed <code>sudo apt install simplescreenrecorder</code> == Docker Installation Guide == === Preparation === Before we begin, make sure...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Please Select a Licence from the LICENCE_HEADERS page
And place at top of your page
If no Licence is Selected/Appended, Default will be CC0

Default Licence IF there is no Licence placed below this notice! When you edit this page, you agree to release your contribution under the CC0 Licence

LICENCE: More information about the cc0 licence can be found here:
https://creativecommons.org/share-your-work/public-domain/cc0

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Licence:

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

   the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
   moral rights retained by the original author(s) and/or performer(s);
   publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
   rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
   rights protecting the extraction, dissemination, use and reuse of data in a Work;
   database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
   other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

   No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
   Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
   Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
   Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.


Starting Environment

  • Hardware: HP EliteDesk 800 G1
  • Operating System: Ubuntu-Mate 24.04
  • Installation Type: Fresh Install
  • Initial Setup Post-Install: Package Update: sudo apt update && sudo apt upgrade -y
  • Additional Software: Installed just to record screen for this tut and not needed sudo apt install simplescreenrecorder

Docker Installation Guide

Preparation

Before we begin, make sure you're logged in with a user account that has sudo privileges.

Update System Packages

Update your package list to ensure you have the latest versions of packages:

sudo apt update

Install Docker Prerequisites

Install the necessary packages for Docker setup:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Setup Docker Repository

  • Add Docker's Official GPG Key:
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • Add the Docker Repository:
  echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker and Docker Compose

  • Update Package List Again:
  sudo apt update
  • Install Docker Engine, CLI, Containerd, and Additional Tools:
  sudo apt install -y docker-ce docker-ce-cli containerd.io python3-bs4 python3-requests docker-compose
  • Install Docker Compose:

Here we're downloading the latest version of Docker Compose:

  sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Make the Docker Compose binary executable:

  sudo chmod +x /usr/local/bin/docker-compose

Verify Installation

Check if Docker and Docker Compose are installed correctly:

docker --version
docker-compose --version

Configure User Permissions

To run Docker commands without sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Note: After adding your user to the docker group, you'll need to log out and log back in for the changes to take effect. If you do not log out and back in, Or you do not add your $USER to the docker group, you will be required to use sudo in some cases. such as ..

Creating a Wiki and Importing an XML Dump

Setup the Wiki Environment

Create Directory for the Wiki

mkdir noobwiki
cd noobwiki

Create Docker Compose File

Edit your docker-compose.yml file:

$EDITOR docker-compose.yml

Contents of docker-compose.yml:

services:
  database:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: my_wiki
      MYSQL_USER: wikiuser
      MYSQL_PASSWORD: wikipass
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
    volumes:
      - ./mysql_data:/var/lib/mysql

  mediawiki:
    image: mediawiki
    ports:
      - 8080:80
    links:
      - database
    volumes:
      - ./mediawiki_data:/var/www/html/images
#      - ./LocalSettings.php:/var/www/html/LocalSettings.php # This line is commented out initially

Note: The LocalSettings.php volume mapping is commented out to prevent automatic creation during initial setup.

Python Script for Setup and XML Import

Script Details

Create a Python script to automate the setup and import process:

$EDITOR setup_and_import.py

Contents of setup_and_import.py:

import os
import time
import requests
from bs4 import BeautifulSoup
import re
import subprocess
import sys

BASE_URL = "https://xml.completenoobs.com/xmlDumps/"

def get_available_dumps():
    response = requests.get(BASE_URL)
    soup = BeautifulSoup(response.text, 'html.parser')
    dumps = []
    for link in soup.find_all('a'):
        href = link.get('href')
        if re.match(r'\d{2}_\d{2}_\d{2}\.Noobs/$', href):
            dumps.append(href.rstrip('/'))
    return sorted(dumps, reverse=True)

def get_dump_files(dump):
    response = requests.get(BASE_URL + dump)
    soup = BeautifulSoup(response.text, 'html.parser')
    files = {}
    for link in soup.find_all('a'):
        href = link.get('href')
        if href.endswith('.xml'):
            files[href] = link.next_sibling.strip()
    return files

def download_file(url, filename):
    response = requests.get(url)
    with open(filename, 'wb') as f:
        f.write(response.content)

def run_command(command):
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    return output.decode(), error.decode(), process.returncode

def setup_mediawiki():
    print("Setting up MediaWiki...")
    os.system("docker-compose up -d")
    time.sleep(10)  # Wait for services to start

    print("Please complete the MediaWiki installation by visiting http://localhost:8080")
    print("Use the following database settings:")
    print("Database host: database")
    print("Database name: my_wiki")
    print("Database username: wikiuser")
    print("Database password: wikipass")
    input("Press Enter when you have completed the installation and downloaded LocalSettings.php...")

    if not os.path.exists('LocalSettings.php'):
        print("LocalSettings.php not found. Please place it in the current directory.")
        sys.exit(1)

    os.system("docker-compose restart mediawiki")
    print("MediaWiki setup completed.")

def import_xml_to_mediawiki(xml_file):
    command = f"docker-compose exec -T mediawiki php maintenance/importDump.php < {xml_file}"
    output, error, return_code = run_command(command)
    if return_code != 0:
        print(f"Error importing XML: {error}")
        sys.exit(1)
    print(output)

def main():
    if not os.path.exists('LocalSettings.php'):
        setup_mediawiki()

    dumps = get_available_dumps()
    print("Available dumps:")
    for i, dump in enumerate(dumps):
        print(f"{i + 1}. {dump}")
    
    choice = int(input("Enter the number of the dump you want to download: ")) - 1
    selected_dump = dumps[choice]
    
    files = get_dump_files(selected_dump)
    xml_file = next(iter(files))
    
    print(f"Downloading {xml_file}...")
    download_file(BASE_URL + selected_dump + '/' + xml_file, xml_file)
    
    print("Importing XML dump into MediaWiki...")
    import_xml_to_mediawiki(xml_file)
    print("Import completed successfully.")

if __name__ == "__main__":
    main()

Running the Script

python3 setup_and_import.py

Terminal Output: when script running at this stage:

noob@noob-elite:~/wiki$ python3 setup_and_import.py 
Setting up MediaWiki...
WARN[0000] /home/noob/wiki/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 33/2
 ✔ database Pulled                                                                                                                                                                      54.0s 
 ✔ mediawiki Pulled                                                                                                                                                                     95.0s 
[+] Running 3/3
 ✔ Network wiki_default        Created                                                                                                                                                   0.1s 
 ✔ Container wiki-database-1   Started                                                                                                                                                   0.3s 
 ✔ Container wiki-mediawiki-1  Started                                                                                                                                                   0.5s 
Please complete the MediaWiki installation by visiting http://localhost:8080
Use the following database settings:
Database host: database
Database name: my_wiki
Database username: wikiuser
Database password: wikipass
Press Enter when you have completed the installation and downloaded LocalSettings.php...




Script Execution Steps

  • Initial Setup: The script starts Docker containers and waits for MediaWiki installation.
  • Manual Steps:
    • Leave the script terminal running.
    • Open a new terminal for further commands.
    • Visit http://localhost:8080 in your browser to complete the MediaWiki setup using:
      • Database host: database
      • Database name: my_wiki
      • Database username: wikiuser
      • Database password: wikipass
  • Post Installation:
    • Download LocalSettings.php from the browser.
    • This Downloads to your Downloads directory, move/copy to your noobwiki directory.
    • Stop the containers:
      • NOTE: docker-compose commands are ment to be run in direcotry containing the docker-compose.yml file Or you need to use docker-compose -f /path/to/docker-compose.yml down -v
docker-compose down -v
    • Uncomment the LocalSettings.php volume mapping in docker-compose.yml.
$EDITOR docker-compose.yml

docker-compose.yml After uncommenting:

services:
  database:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: my_wiki
      MYSQL_USER: wikiuser
      MYSQL_PASSWORD: wikipass
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
    volumes:
      - ./mysql_data:/var/lib/mysql

  mediawiki:
    image: mediawiki
    ports:
      - 8080:80
    links:
      - database
    volumes:
      - ./mediawiki_data:/var/www/html/images
      - ./LocalSettings.php:/var/www/html/LocalSettings.php # This line is commented out initially
    • Restart Docker:
docker-compose up -d
  • Return to Script Terminal:
    • Press Enter to continue with XML dump selection and import.

Post LocalSettings.php script

After returning to script and pressing Enter, the script will scan xml.completenoobs.com and give you a list of wiki dumps with a Number on the left and a date.

  • Enter number to select a dated xml
Press Enter when you have completed the installation and downloaded LocalSettings.php...
[+] Restarting 1/1
 ✔ Container wiki-mediawiki-1  Started                                                   1.3s 
MediaWiki setup completed.
Available dumps:
1. 31_05_23.Noobs
2. 30_03_23.Noobs
3. 28_04_24.Noobs
4. 28_04_23.Noobs
5. 26_06_23.Noobs
6. 26_05_23.Noobs
7. 26_04_23.Noobs
8. 23_04_23.Noobs
9. 23_03_23.Noobs
10. 21_06_23.Noobs
11. 21_05_23.Noobs
12. 21_04_23.Noobs
13. 20_03_23.Noobs
14. 17_04_23.Noobs
15. 16_06_23.Noobs
16. 16_05_23.Noobs
17. 11_07_23.Noobs
18. 11_06_23.Noobs
19. 11_05_23.Noobs
20. 06_07_23.Noobs
21. 06_06_23.Noobs
22. 06_05_23.Noobs
23. 04_05_23.Noobs
24. 01_07_23.Noobs
25. 01_06_23.Noobs
26. 01_05_23.Noobs
Enter the number of the dump you want to download: 3
Downloading 28_04_24.Noobs.xml...
Importing XML dump into MediaWiki...
Done!
You might want to run rebuildrecentchanges.php to regenerate RecentChanges,
and initSiteStats.php to update page and revision counts

Import completed successfully.

Post-Setup Maintenance

Now, we need to rebuild our wiki so that the database reflects our imported content.

Login to Container for Maintenance

  • Syntax:docker exec -it <directory_name>-<service>-1 /bin/bash
    • use:docker container ls to see container and service names.
docker exec -it noobwiki-mediawiki-1 /bin/bash
  • Run maintenance scripts:
php maintenance/initSiteStats.php
php maintenance/rebuildrecentchanges.php
php maintenance/rebuildall.php
  • Exit the container:
exit

Verify Wiki Content

  • Check all pages have loaded by visiting:
http://127.0.0.1:8080/index.php/Special:AllPages


Here's the section in raw MediaWiki syntax:

Network Configuration

By default, your wiki might only be accessible from the host machine where Docker is running, using localhost or 127.0.0.1. However, if you want others on your network to access your wiki, you need to make some adjustments.

Current Setup: The computer running Docker Compose has an IP address of 192.168.0.44.

  • You can find the IP address of your computer running Docker using the command:

ip addr

OutPut from ip addr

noob@noob-HP-EliteDesk-800-G1-DM:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute 
       valid_lft forever preferred_lft forever
2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 8c:dc:d4:3d:93:49 brd ff:ff:ff:ff:ff:ff
    altname enp0s25
3: wlxe8de27142be2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether e8:de:27:14:2b:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.44/24 brd 192.168.0.255 scope global dynamic noprefixroute wlxe8de27142be2
       valid_lft 86357sec preferred_lft 86357sec
    inet6 fe80::afbe:cc73:73a2:fcdf/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

My IP is 192.168.0.44

If someone from another computer on the network tries to visit 192.168.0.44:8080, they might encounter a "cannot connect" error. This happens because MediaWiki, by default, redirects to 127.0.0.1:8080, which is only accessible from the host machine itself.

Solution: To allow access from other devices on the same network, you need to:

  • Edit the LocalSettings.php File: This isn't done inside the Docker container but rather in the directory where your docker-compose.yml file is located. Here, you need to change the server URL configuration.
  • Modify URL Configuration: On lines 34-35 of LocalSettings.php, you'll find the following:

Allowing Access from Other Network Devices

  • Edit LocalSettings.php in the Docker Compose directory to change the server URL:
## The protocol and server name to use in fully-qualified URLs
$wgServer = 'http://192.168.0.44:8080';
  • Restart Docker to apply changes:
docker-compose restart

This allows access to your wiki from other devices on the network using 192.168.0.44:8080. This adjustment tells MediaWiki to use the network IP of the host (192.168.0.44) instead of the local loopback (127.0.0.1), allowing other devices on the network to access the wiki through 192.168.0.44:8080. Even after this change, localhost:8080 or 127.0.0.1:8080 will still work on the host machine, but now the wiki is also accessible via the network IP from other devices.