Creating a LAMP server with Ubuntu 16.04

Here are some of the guides and resources I used to get my site working the way that I wanted.

Install a LAMP server (Linux-Apache-MySQL-PHP) as a prerequisite for installing WordPress.

https://www.ubuntu.com/download/desktop

Ubuntu 16.04

sudo apt-get update
sudo apt-get install apache2
sudo nano /etc/apache2/apache2.conf

Add the line:

ServerName server_domain_or_IP

CTRL+O & CTRL+X to save and quit

sudo apache2ctl configtest

Verify Output syntax OK

sudo systemctl restart apache2

Configure and check firewall to allow HTTP/HTTPS traffic:

sudo ufw allow in "Apache Full"

Browse to http://your_server_IP_address and verify Apache default page appears.

Install MySQL

sudo apt-get install mysql-server

Create secure password for MySQL root user. Run following script to further secure MySQL:

mysql_secure_installation

Select level 2 of password validation for STRONG password requirements.

Install PHP

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

Modify dir.conf to look for PHP files before HTML:

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

Move the “index.php” to come directly after “DirectoryIndex”:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Restart Apache web service:

sudo systemctl restart apache2

Test PHP Processing with info.php and then remove it:

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

This will create a new blank file. Enter the following and save and quit nano:

<?php
phpinfo();
?>

Now browse your website from another machine.

http://your_server_IP_address/info.php

You will see a PHP informational page with status of your installed modules. If all is well, remove the info.php file.

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

Secure the site with SSL to enforce HTTPS. First add the repository.

sudo add-apt-repository ppa:certbot/certbot

Now update the repository and install Certbot

sudo apt-get update
sudo apt-get install python-certbot-apache

Configure certbot to install a certificate that covers the base domain and standard www sub domain.

sudo certbot --apache -d example.com -d www.example.com

Follow the step by step guide to configure the certificate options including an lost key recovery email address. Enable force all requests to redirect to HTTPS. The generated file will be found at /etc/letsencrypt/live. The certbot install script also places a auto renewal task in /etc/cron.d that auto renews the SSL certificate. Test the renewal process with a dry run:

sudo certbot renew --dry-run

Now we have a web server ready. The next step may be to Install and Configure WordPress.