NGINX Unit
v. 1.18.0

MediaWiki§

To install a MediaWiki server using Unit:

  1. Install Unit with a PHP language module.

  2. Check and configure MediaWiki’s prerequisites.

  3. Download and extract MediaWiki files:

    $ mkdir -p /path/to/mediawiki/ /tmp/mediawiki/ && cd /tmp/mediawiki/
    $ curl -O https://releases.wikimedia.org/mediawiki/1.34/mediawiki-1.34.1.tar.gz
    $ tar xzf mediawiki-1.34.1.tar.gz --strip-components 1 -C /path/to/mediawiki/
    # chown -R mw_user:mw_group /path/to/mediawiki/
    

    In this example, the files will be stored in /path/to/mediawiki/.

  4. Next, prepare and upload the app configuration to Unit:

    {
        "listeners": {
            "*:80": {
                "pass": "routes/mediawiki"
            }
    
        },
    
        "routes": {
            "mediawiki": [
                {
                    "match": {
                        "uri": [
                            "!/tests/qunit/*",
                            "/cache/*",
                            "/includes/*",
                            "/languages/*",
                            "/maintenance/*",
                            "/tests/*",
                            "/vendor/*"
                        ]
                    },
    
                    "action": {
                        "return": 403
                    }
                },
                {
                    "match": {
                        "uri": [
                            "/api.php*",
                            "/img_auth.php*",
                            "/index.php*",
                            "/load.php*",
                            "/mw-config/*.php",
                            "/opensearch_desc.php*",
                            "/profileinfo.php*",
                            "/rest.php*",
                            "/tests/qunit/*.php",
                            "/thumb.php*",
                            "/thumb_handler.php*"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/mw/direct"
                    }
                },
                {
                    "match": {
                        "uri": [
                            "!*.php",
                            "!*.json",
                            "!*.htaccess",
                            "/extensions/*",
                            "/images/*",
                            "/resources/assets/*",
                            "/resources/lib/*",
                            "/resources/src/*",
                            "/skins/*"
                        ]
                    },
    
                    "action": {
                        "share": "/path/to/mediawiki/"
                    }
                },
                {
                    "action": {
                        "pass": "applications/mw/index"
                    }
                }
            ]
        },
    
        "applications": {
            "mw": {
                "type": "php",
                "user": "mw_user",
                "targets": {
                    "direct": {
                        "root": "/path/to/mediawiki/"
                    },
    
                    "index": {
                        "root": "/path/to/mediawiki/",
                        "script": "index.php"
                    }
                }
            }
        }
    }
    

    Note

    The difference between the pass targets is their usage of the script setting:

    • The direct target runs the .php script from the URI or defaults to index.php if the URI omits it.
    • The index target specifies the script that Unit runs for any URIs the target receives.
  5. Assuming the config above is saved as mediawiki.json:

    # curl -X PUT --data-binary @mediawiki.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
    
  6. Browse to /mw-config/index.php to configure the settings from Step 2 and complete your installation:

    MediaWiki on Unit

    Download the LocalSettings.php file created here and place it appropriately:

    $ mv LocalSettings.php /path/to/mediawiki/
    $ chmod 600 /path/to/mediawiki/LocalSettings.php
    # chown mw_user /path/to/mediawiki/LocalSettings.php
    
  7. After installation, add a match condition to the first step to disable access to the mw-config/ directory:

    # curl -X POST -d '"/mw-config/*"' --unix-socket \
           /path/to/control.unit.sock                \
           http://localhost/config/routes/mediawiki/0/match/uri/
    
          {
              "success": "Reconfiguration done."
          }
    

    Finally, your wiki is ready!

    MediaWiki on Unit