Overview#
This guide covers installing MediaWiki on an Alpine Linux container running in Proxmox. The stack is Apache with php-fpm, MariaDB, APCu object caching, and PHP OPcache.
Steps at a glance:
- Prepare the container
- Install Apache
- Install PHP
- Install and configure MariaDB
- Download MediaWiki
- Switch Apache to php-fpm
- Install the APCu extension
- Secure the upload directory
- Run the MediaWiki installer
- Enable PHP OPcache
Replace these placeholders throughout:
| Placeholder | Meaning |
|---|---|
username | Your Linux admin username |
username_wiki | The MariaDB user for the wiki |
password | The MariaDB wiki user’s password |
IP_ADDRESS | The container’s IP address |
1. Prepare the Container#
Turn on the firewall#
In the Proxmox web interface, assign the container to the appropriate security groups and turn on its firewall.
Create an admin user with doas#
doas is a lightweight alternative to sudo. As root:
Install
doas:apk add doasCreate your user (enter a password when prompted) and add it to the
wheelgroup:adduser username adduser username wheelOpen the doas config:
vi /etc/doas.d/doas.confAdd this line at the end so
wheelmembers can use root privileges throughdoas, then save and close:permit persist :wheelSwitch to the new account:
su - usernameTest
doas. Enter your password when prompted and confirm thatviopens:doas vi test.txtType
exittwice to leave the new account and then the root session. Confirm you can no longer log in as root, then log in as your new user.
Install updates#
doas apk update
doas apk upgradeLock the root account#
doas passwd -l rootSet the timezone#
Install the timezone database, point /etc/localtime at the Central zone (creating the symlink), and write the zone name to /etc/timezone as a plain-text record:
doas apk add tzdata
doas ln -sf /usr/share/zoneinfo/CST6CDT /etc/localtime
echo "CST6CDT" | doas tee /etc/timezoneUse
teefor the last command. Withdoas echo "CST6CDT" > /etc/timezone, the>redirect still runs as your user and fails with “Permission denied.”
Install the OpenRC init system#
doas apk add openrc2. Install Apache#
Install Apache, start it, and enable it at boot:
doas apk add apache2 doas rc-service apache2 start doas rc-update add apache2Browse to
http://IP_ADDRESSand confirm you see the “It works” page.
3. Install PHP#
Install PHP, its extensions, curl, ImageMagick, and diffutils:
doas apk add curl php php-mysqli php-dom php-apache2 php-mbstring php-fpm php-ctype php-json php-curl php-fileinfo php-iconv php-intl php-session php-gd php-xml php-xmlreader php-xmlwriter imagemagick diffutilsOptional: Older guides also set a PHP version variable as shown below. It isn’t needed for this install.
export phpverx=$(alpinever=$(cat /etc/alpine-release|cut -d '.' -f1);[ $alpinever -ge 9 ] && echo 7|| echo 5)Restart Apache:
doas rc-service apache2 restartCreate a test page in the web root:
cd /var/www/localhost/htdocs/ doas vi phpinfo.phpPress
ito insert, then paste:<?php echo phpinfo(); ?>Browse to
http://IP_ADDRESS/phpinfo.php. A PHP configuration page means Apache and PHP are working together.Delete the test file:
doas rm phpinfo.php
4. Install and Configure MariaDB#
Install MariaDB and run its initial setup:
doas apk add mysql mysql-client doas /etc/init.d/mariadb setupStart it and enable it at boot:
doas rc-service mariadb start doas rc-update add mariadb defaultSecure the installation:
doas mysql_secure_installationWhen prompted:
- Switch to
unix_socketauthentication - Change the MariaDB root password
- Remove anonymous user accounts
- Disable remote root logins
- Remove test databases
- Switch to
Connect as root (enter the root password when prompted):
mariadb -u root -pCreate the wiki database and user, then grant access:
CREATE DATABASE my_wiki; CREATE USER 'username_wiki'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON my_wiki.* TO 'username_wiki'@'localhost' WITH GRANT OPTION;Type
exitto leave MariaDB.
5. Download MediaWiki#
Check the MediaWiki download page for the current release, and set these two variables to match it. The values below are an example for the 1.43 long-term support (LTS) branch:
MW_BRANCH=1.43 MW_VERSION=1.43.6MediaWiki 1.45 and later require PHP 8.2 or newer. The PHP 8.3 packages used in this guide meet that requirement.
Create the webapps directory and download MediaWiki from your home directory:
doas mkdir -p /usr/share/webapps/ cd /home/username/ doas curl https://releases.wikimedia.org/mediawiki/${MW_BRANCH}/mediawiki-${MW_VERSION}.tar.gz >mw.tar.gzMove the archive into place, unpack it, rename the folder, and delete the tarball:
doas mv mw.tar.gz /usr/share/webapps/ cd /usr/share/webapps/ doas tar zxvf mw.tar.gz doas mv mediawiki-${MW_VERSION} mediawiki doas rm mw.tar.gzGive the
apacheuser ownership and link MediaWiki into the web root:doas chown -R apache /usr/share/webapps/ doas ln -s /usr/share/webapps/mediawiki/ /var/www/localhost/htdocs/mediawikiRestart Apache:
doas rc-service apache2 restart
6. Switch Apache to php-fpm#
Based mostly on the Alpine Linux wiki article Apache with php-fpm.
Install the Apache proxy module and php-fpm, then start php-fpm and enable it at boot:
doas apk add apache2-proxy php-fpm doas rc-service php-fpm83 start doas rc-update add php-fpm83Edit the main Apache config:
doas vi /etc/apache2/httpd.confEnable the event MPM by removing the leading
#:LoadModule mpm_event_module modules/mod_mpm_event.soMake sure the prefork MPM is commented out:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.soAdd this to the bottom of the file, then save and close:
<FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9000" </FilesMatch>
Disable mod_php. Open its config:
doas vi /etc/apache2/conf.d/php83-module.confComment out these lines, then save and close:
#LoadModule php_module modules/mod_php8.so #DirectoryIndex index.php index.html #<FilesMatch \.php$> # SetHandler application/x-httpd-php #</FilesMatch>Set php-fpm to run as
apache. Open the pool config:doas vi /etc/php83/php-fpm.d/www.confSet these values, then save and close:
user = apache group = apacheRestart both services:
doas rc-service php-fpm83 restart && doas rc-service apache2 restart
7. Install the APCu Extension#
Adapted from “How to Install PHP APCu on Ubuntu 16.04”.
Check whether APCu is already installed. If this returns nothing, continue:
php -m | grep -i apcuInstall the packages
peclneeds:doas apk --no-cache add php-pear php83-dev gcc musl-dev makeInstall APCu. Answer
nowhen asked about debugging:doas pecl install apcuOpen the PHP config:
doas vi /etc/php83/php.iniAdd this line to the bottom of the file:
extension=apcu.soVerify APCu is enabled, then restart both services:
php -m | grep -i apc doas rc-service php-fpm83 restart doas rc-service apache2 restart
8. Secure the Upload Directory#
Stop scripts from running in MediaWiki’s images upload directory.
Open the Apache config:
doas vi /etc/apache2/httpd.confThe
Headerdirective in the block below needs Apache’s headers module. Find this line and make sure it’s uncommented (no leading#):LoadModule headers_module modules/mod_headers.soWithout this module, Apache will fail to start with an “Invalid command ‘Header’” error.
Add this block anywhere in the file:
<Directory "/var/www/localhost/htdocs/mediawiki/images"> # Ignore .htaccess files AllowOverride None # Serve HTML as plaintext, don't execute SHTML AddType text/plain .html .htm .shtml .phtml .php .php3 .php4 .php5 .php7 # Old way of registering php with AddHandler RemoveHandler .php # Recent way of registering php with SetHandler <FilesMatch "\.ph(p[3457]?s?|tml)$"> SetHandler None </FilesMatch> # Tell browsers to not sniff files Header set X-Content-Type-Options nosniff </Directory>Save and close, then restart Apache:
doas rc-service apache2 restart
9. Run the MediaWiki Installer#
Browse to:
http://IP_ADDRESS/mediawiki/mw-config/index.phpFill out the installation form. Make sure to:
- Set the wiki type to Private Wiki
- Select VisualEditor
- Under Settings for Object Caching, select PHP object caching (APC, APCu or WinCache)
On the final page, the installer downloads
LocalSettings.php. Open it in a text editor on your local machine and copy its contents.On the container, create the file in the MediaWiki directory:
cd /usr/share/webapps/mediawiki/ doas vi LocalSettings.phpPress
ito insert, paste the contents, and check that everything pasted correctly from top to bottom.Confirm
$wgMainCacheTypeis set toCACHE_ACCEL, then save and close:$wgMainCacheType = CACHE_ACCEL;Restart both services:
doas rc-service php-fpm83 restart doas rc-service apache2 restart
10. Enable PHP OPcache#
Install the OPcache extension:
doas apk add php-opcacheOpen the PHP config:
doas vi /etc/php83/php.iniFind and uncomment these lines, then save and close:
opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=10000 opcache.revalidate_freq=200Restart Apache:
doas rc-service apache2 restart
Accessing MediaWiki#
Once setup is complete, MediaWiki is available at:
http://IP_ADDRESS/mediawikihttp://wiki.home.lan(local DNS name)
Troubleshooting#
A directory listing appears instead of the wiki#
If http://IP_ADDRESS/mediawiki shows a mediawiki/ directory listing:
Open the Apache config:
doas vi /etc/apache2/httpd.confFind this block and change
index.htmltoindex.php, then save and close:<IfModule dir_module> DirectoryIndex index.php </IfModule>Restart Apache:
doas rc-service apache2 restart