The following code is for Debian 9 Stretch but should work on older Debian with minor changes
#!/bin/sh
# LAMP_Setup.sh
#
#
# Created by David Kittell on 1/18/18.
#
sudo apt -y update
sudo apt -y upgrade
sudo apt install -y apache2 apache2-utils
systemctl status apache2
sudo systemctl start apache2
sudo systemctl enable apache2
sudo apache2 -v
sudo apt install -y curl
publicIP=$(curl -s https://kittell.net/ip.php)
echo $publicIP
sudo chown www-data:www-data /var/www/html/ -Rv
sudo apt install -y mariadb-server mariadb-client
systemctl status mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
mariadb --version
sudo apt install -y php libapache2-mod-php php-mysql php-common php-cli php-common php-json php-opcache php-readline
sudo a2enmod php
sudo systemctl restart apache2
php --version
echo "<?PHP phpinfo() ?>" | sudo tee /var/www/html/info.php
Last Updated on January 31, 2019