This will install Mediawiki in Lightsail. I’m assuming you already setup SSH access.

Install LAMP

To speed up things with the rest of the software below, run this:

sudo apt update
sudo apt upgrade
sudo apt-get install apache2 imagemagick php-cli libapache2-mod-php mysql-server php php-apcu php-mcrypt php-mysql php7.0-intl php7.0-mbstring php7.0-xml python-certbot-apache

This is around 400Mb of software, but takes around four minutes to install.

Apache

Here I’m using the domain jano.com.es. You can use your own domain, static IP, or made-up domain if you add it to /etc/hosts.

Install Apache

sudo apt update
sudo apt upgrade
sudo apt-get install apache2

Edit Apache configuration

sudo nano /etc/apache2/apache2.conf

Add this at the bottom

ServerName jano.com.es

Check for errors and restart Apache

sudo apache2ctl configtest
sudo systemctl restart apache2

UFW

UFW is the Uncomplicated Firewall of Ubuntu. As the name suggests, it is easy to use.

Check that the UFW firewall has a profile for Apache

sudo ufw app list

Check that the UFW firewall has an “Apache Full” profile that enables ports 80 and 443:

sudo ufw app info "Apache Full"

Only if you want to change the port from 80 to 90, you have to change the number in /etc/apache2/ports.conf, and /etc/apache2/sites-enabled/000-default.conf. Then you have to change the port to :90

sudo ufw allow 90/tcp

Check that the Apache2 Ubuntu default page is accessible through your firewall at your server IP: http://jano.com.es (use your domain or IP).

This should show the public machine IP but doesn’t. I guess the instance is in a container with its own gateway and network.

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

We can check the public IP on teh cosole, or just run:

curl http://icanhazip.com

Let’s Encrypt

If you have a domain and want to install a SSL certificate, Let’s Encrypt offers certificates for free. This will need port 80 access.

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get install python-certbot-apache
sudo certbot --apache -d jano.com.es
sudo certbot --apache -d jano.com.es -d jano.com.es

MySQL

Install MySQL:

sudo apt-get install mysql-server

Optionally run a script to secure MySQL:

mysql_secure_installation

PHP

Now installing PHP in Apache:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Tell Apache to serve index.php before the default index.html. Edit the /etc/apache2/mods-enabled/dir.conf file and put the index.php first.

sudo nano /etc/apache2/mods-enabled/dir.conf

Restart Apache:

sudo systemctl restart apache2

Check the status of Apache. If you don’t see any errors it’s fine.

sudo systemctl status apache2

Check that PHP works. Create a php page:

sudo nano /var/www/html/info.php

with this content:

<?php
phpinfo();
?>

Load the page: http://jano.com.es/info.php

Now remove it to prevent intruders from gaining info about the server:

sudo rm /var/www/html/info.php