Manual:Swift

MediaWiki can store files in OpenStack Swift. The following are instructions for installing Swift for local development or a single-server production install.

On your Debian or Ubuntu system (tested on Ubuntu 22.04), as root:

# Install packages
apt-get install swift swift-account swift-container swift-object swift-object-expirer \
  swift-proxy python3-swiftclient memcached

# The package has object-server on port 6000, container-server on port 6001,
# account-server on 6002. Let's put the proxy server on port 6006.

# Generate the rings, with a minimum number of partitions.
# Call the device "dev0". With mount_check=false this just needs to be a
# directory on a filesystem with xattr support.

cd /etc/swift
swift-ring-builder object.builder create 0 1 1
swift-ring-builder object.builder add r1z1-127.0.0.1:6000/dev0 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 0 1 1
swift-ring-builder container.builder add r1z1-127.0.0.1:6001/dev0 1
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 0 1 1
swift-ring-builder account.builder add r1z1-127.0.0.1:6002/dev0 1
swift-ring-builder account.builder rebalance

printf '[swift-hash]\nswift_hash_path_suffix=%s\nswift_hash_path_prefix=%s\n' \
  $(openssl rand -hex 4) $(openssl rand -hex 4) > swift.conf

# Default data directory is /srv/node. Let's use /data/swift instead.

install -o swift -g swift -d /data/swift/dev0
sed -i '4a\
devices=/data/swift\
mount_check = false' container-server.conf object-server.conf account-server.conf

# The proxy configuration is fiddly. You need to tell it not only what features to
# enable, but also what order the features need to be loaded into a middleware
# pipeline, and how to locate its own classes.

user_key=$(openssl rand -hex 8)
admin_key=$(openssl rand -hex 8)
cat '[DEFAULT]
bind_port = 6006
workers = 2

[pipeline:main]
pipeline = catch_errors gatekeeper proxy-logging listing_formats healthcheck cache container_sync tempurl ratelimit tempauth copy dlo versioned_writes proxy-logging proxy-server

[filter:catch_errors]
use = egg:swift#catch_errors

[filter:gatekeeper]
use = egg:swift#gatekeeper

[filter:listing_formats]
use = egg:swift#listing_formats

[filter:healthcheck]
use = egg:swift#healthcheck

[filter:cache]
use = egg:swift#memcache

[filter:container_sync]
use = egg:swift#container_sync

[filter:tempurl]
use = egg:swift#tempurl

[filter:ratelimit]
use = egg:swift#ratelimit

[filter:tempauth]
use = egg:swift#tempauth
user_admin_admin = '$admin_key' .admin .reseller_admin
user_mw_media = '$user_key' .admin

[filter:copy]
use = egg:swift#copy

[filter:dlo]
use = egg:swift#dlo

[filter:versioned_writes]
use = egg:swift#versioned_writes

[filter:proxy-logging]
use = egg:swift#proxy_logging

[app:proxy-server]
use = egg:swift#proxy
account_autocreate = true
' > proxy-server.conf

# The servers can be started now
systemctl start swift-object swift-container swift-account swift-proxy

In LocalSettings.php:

$wgFileBackends[] = [
	'class' => SwiftFileBackend::class,
	'name' => "local-swift",
	'swiftAuthUrl' => 'http://localhost:6006/auth',
	'swiftUser' => 'mw:media',
	'swiftKey' => $user_key,
	'parallelize' => 'implicit',
	'cacheAuthInfo' => true,
	'lockManager' => 'memcLockManager',
];
$wgLocalFileRepo = [
	'class' => LocalRepo::class,
	'name' => 'local',
	'backend' => 'local-swift',
	'url' => '/images',
];
$wgLockManagers[] = [
	'name' => 'memcLockManager',
	'class' => MemcLockManager::class,
	'lockServers' => [ '127.0.0.1:11211' ],
];

The default lock manager uses the filesystem, which is inconvenient for a Swift-backed wiki. Above, we used memcached. The server is shared with Swift. Production uses Redis, but that would need to be set up separately.

The web server hosting MediaWiki needs to proxy certain paths to Swift:

<Location "/images">
        ProxyPass "http://localhost:6006/v1/AUTH_mw/mw_swift-local-public"
</Location>
<Location "/images/thumb">
        ProxyPass "http://localhost:6006/v1/AUTH_mw/mw_swift-local-thumb"
</Location>

And that's it. You should be able to upload files to the wiki.