#!/bin/bash
echo "Installing LAMP stack..."

# Install a LAMP Stack on a Debian server
# By Robbie Ferguson // baldnerd.com

if [[ $EUID -ne 0 ]]; then
  echo "ERROR: This script must be run as root" 2>&1
  exit 1
fi

# Update apt repositories
sudo apt update > /dev/null 2>&1

# Install the LAMP base
yes | sudo apt install apache2 php php-cli php-common php-curl php-gd php-json php-mbstring php-mysql php-opcache php-phpdbg php-readline php-sqlite3 php-xml libapache2-mod-php libargon2-1 libsodium23 php-curl php-rrd mariadb-server libapache2-mod-security2 modsecurity-crs

# Install CSF/LFD Firewall
yes | sudo apt install iptables
cd /usr/src
wget -O /tmp/csf.tgz https://download.configserver.com/csf.tgz
tar -xzf /tmp/csf.tgz
cd csf
sh install.sh
# Load base configuration from NEMS Linux to open common ports and ignore local IP addresses
wget -O /etc/csf/csf.conf https://github.com/NEMSLinux/nems-migrator-data/raw/main/debpack/root/nems/nems-migrator/data/csf/csf.conf
wget -O /etc/csf/csf.ignore https://github.com/NEMSLinux/nems-migrator-data/raw/main/debpack/root/nems/nems-migrator/data/csf/csf.ignore
# Enable and Re/start CSF
csf -e
csf -R

# Add a root password to MySQL
sudo mysql_secure_installation

echo "Done."