Some notes for future reference next time I setup a new EC2 instance....

EC2 instance tools


Add amazon-linux-extras
$ sudo yum install amazon-linux-extras

Install PHP 7.4

Using amazon-linux-extras installed previously to install PHP7.4
$ sudo amazon-linux-extras enable php7.4
$ sudo yum clean metadata
$ sudo yum install php-cli php-pdo php-fpm php-json php-common php-pear php-gd php-curl php-zip php-mbstring php-mysqlnd

Adding MariaDB

Amazon would rather you use RDS for MySQL/MariaDB/Aurora. This is probably the correct architectural approach for large sites that have the budget to run RDS instances, however most of my personal/freelance sites don't the need or budget for that.

For low traffic sites, installing MariaDB on the same ec2 instance works, but bear in mind if your site grows in popularity you will probably want to migrate your DB to RDS.

Using amazon-linux -extras

$ amazon-linux-extras list | grep mariadb
_ lamp-mariadb10.2-php7.2 available \
54 mariadb10.5 available [ =stable ]

So here we can see mariadb10.5 is available via amazon-linux-extras, so lets go ahead and install it.

Enable the topic in amazon-linux-extras: $ amazon-linux-extras enable mariadb10.5

That will list available topics and you should see mariadb10.5 is showing as enabled, now we can install the software.
$ yum clean metadata
$ yum install mariadb
Check version: $ mysql -v
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4 Server version: 10.5.10-MariaDB MariaDB Server

You might want to enable the server to start with the machine: $ systemctl enable mariadb.service

Using MariaDB yum repository

Prefer to use amazon-linux-extras rather than mariadb repo installation.

Worth noting this is installing as if Centos7, not Amazon linux 2.
This may lead to issues later due to AMZ Linux vs Centos, but as far as I could see the only MariaDB install provided properly for Amazon Linux is an old version (5.x) in the Amazon repositories. So I decided to give it a go with the Centos version.

Check latest version of Maria DB on the MariaDB website. You can also get template versions of repo files there too.

$ sudo vi /yum/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Enable the MariaDB service as default and start it now:
$ sudo systemctl enable mariadb.service
$ systemctl start mariadb.service


Secure MariaDB server using the provided tool and follow prompts:
$ sudo mysql_secure_installation

Installing MariaDB on Amazon Linux

Install and enable web server

$ sudo yum install httpd httpd-tools mod-ssl
$ sudo systemctl enable httpd.service
$ sudo systemctl start httpd.service

Test by creating an index.html in /var/www/html
That file should have appropriate permissions to be servable
$ sudo chmod 755 /var/www/html/index.html

There are a million and one ways to setup users and permissions.
I just change owner of web files to apache, largely through ignorance. I'm sure someone will tell me there are good reasons not to do that and what a better way would be. We certainly don't want these files to be owned by root.

$ sudo chown apache:apache /var/www/html/*

Tweak your web server config to suit your needs. Check out the Apache documentation but as this is a page of notes for me as much as anyone I'll add some tweaks below:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>