This will install Mediawiki in Lightsail. I’m assuming you already setup SSH, and LAMP. Otherwise read my previous posts.

Mediawiki

Useful apt packages

sudo apt install imagemagick php-cli php-apcu
sudo apt install php7.0-mbstring
sudo apt install php7.0-xml
sudo phpenmod mbstring
sudo phpenmod xml

The configuration is at /etc/php/7.0/apache2/php.ini. We don’t need to change anything now.

Install fastcgi

libapache2-mod-fastcgi

Enable Apache modules proxy, proxy_http, and rewrite. Then restart Apache.

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo service apache2 restart
sudo a2enmod ssl

If you ever need to edit the Apache configuration, it is at /etc/apache2/apache2.conf.

Possibly you’ve seen Perl bitterly complaining that its language is not configured. It doesn’t really matter, but you can solve it adding this to ~/.bashrc:

export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

See that LocalSettings.php points to the database and has the correct password.

sudo nano /var/www/notes/LocalSettings.php

Decompress the mediawiki distribution in the directory /var/www/wikijano (replace wikijano for whatever you see fit).

cd /var/www/
sudo curl https://releases.wikimedia.org/mediawiki/1.29/mediawiki-1.29.1.tar.gz -o mediawiki-1.29.1.tar.gz
sudo tar -zxvf mediawiki-1.29.1.tar.gz
sudo mv mediawiki-1.29.1 wikijano
sudo chown -R root:root wikijano

To point Apache to the mediawiki directory

  • Edit /etc/apache2/sites-available/000-default.conf
  • Replace DocumentRoot /var/www/html with DocumentRoot /var/www/wikijano
  • Restart Apache with sudo systemctl restart apache2.

Now open the domain in your browser. Mediawiki will initiate the configuration through a web interface. You will need the password you installed MySQL with. Once you are done the server will produce a file LocalSettings.php. To complete the installation you have to copy this file to /var/www/wikijano/LocalSettings.php. You can do this with Transmit, scp, rsync, or copy paste through the clipboard.

At this point your mediawiki should be up and running.

Change upload file size limit

Add the following to /var/www/notes/LocalSettings.php

$wgMaxUploadSize = 10485760; # 10Mb

Add the following to /etc/php/7.0/apache2/php.ini

upload_max_filesize = 10M
post_max_size = 10M

Restart Apache2

sudo systemctl restart apache2

Good to know

How to reset MySQL password

# Stop MySQL
sudo service mysql stop
 
# create a directory for the MySQL service
sudo mkdir /var/run/mysqld
 
# change the owner of the service directory
sudo chown mysql: /var/run/mysqld
 
# Start MySQL without permissions or network
sudo mysqld_safe --skip-grant-tables --skip-networking &
 
# Log without password
mysql -uroot mysql

Run this SQL. Replace SECRET with your own password.

UPDATE mysql.user SET authentication_string=PASSWORD('SECRET'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
EXIT;

Start MySQL normally:

# start MySQL
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
 
# start MySQL normally
sudo service mysql start

How to reset mediawiki password

cd /var/www/wikijano
sudo php ./maintenance/changePassword.php --user="jano" --password="SECRETO"

How to backup mediawiki

Create a script with the following content:

#!/bin/bash

BACKUP_DIR=~/backup
BACKUP_MYSQL_DIR=$BACKUP_DIR/mysql
BACKUP_WWW_DIR=$BACKUP_DIR/www
BACKUP_RSYNC_DIR=$BACKUP_DIR/rsync

mkdir -p $BACKUP_DIR
mkdir -p $BACKUP_MYSQL_DIR
mkdir -p $BACKUP_WWW_DIR
mkdir -p $BACKUP_RSYNC_DIR

ssh ubuntu@lightsail mysqldump -u root --password=yourpasswordhere --single-transaction -B notes | gzip > $BACKUP_MYSQL_DIR/`date +%m_%d_%y`_notes.gz
rsync --delete --exclude='Maildir' --exclude='mailbox' --progress -aqhe ssh ubuntu@lightsail:/var/www $BACKUP_RSYNC_DIR
tar -czf $BACKUP_WWW_DIR/web_`date +%m_%d_%y`.tgz $BACKUP_RSYNC_DIR

echo Lightsail backup is done.

exit 0

The script will output the following

mysqldump: [Warning] Using a password on the command line interface can be insecure.
tar: Removing leading '/' from member names
Lightsail backup is done.