Last active
September 16, 2017 18:35
-
-
Save lcherone/cf57d20412fc6b0ac072a584bbdb3fdd to your computer and use it in GitHub Desktop.
LAMP - Apache2 (rewrite, headers enabled), PHP7, MariaDB, Git, Composer, nodejs, npm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
set -e | |
export DEBIAN_FRONTEND=noninteractive | |
source /etc/environment && export PATH && export HOME='/root' | |
# Set working vars, change these to suit | |
# | |
# Application Name | |
appname="My Deployment" | |
installpath="/var/www/html" | |
timezone="Europe/London" | |
# | |
# database - root | |
rootdbpass=$(date +%s%N | sha256sum | base64 | head -c 32 ; echo) | |
# | |
# database - app | |
dbname="app" | |
dbuser="app" | |
dbpass=$(date +%s%N | sha256sum | base64 | head -c 32 ; echo) | |
# | |
# | |
installed=`date +%Y-%m-%d`; | |
# Apache2 | |
write_info() { | |
if ! echo " | |
============================== | |
= $appname | |
= | |
= Installed Date: $installed | |
= Installed Path: $installpath | |
= | |
= MariaDB (mysql) Credentials | |
= - Root Password: $rootdbpass | |
= - | |
= - Database: $dbname | |
= - User: $dbuser | |
= - Password: $dbpass | |
" > $installpath/../install-info.txt | |
then | |
echo "There was an error when creating install-info.txt" | |
exit; | |
else | |
echo "File install-info.txt created." | |
fi | |
} | |
# Setup & Install Dependencys | |
setup_system() { | |
# | |
# set timezone | |
echo $timezone > /etc/timezone | |
dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>/dev/null | |
# | |
# Update System | |
sudo apt-get update | |
sudo apt-get -yq upgrade | |
# | |
# Install system packages | |
sudo apt-get -yq install curl wget | |
sudo apt-get -yq install unzip | |
sudo apt-get -yq install git | |
sudo apt-get -yq install nano | |
sudo apt-get -yq install htop | |
} | |
# Apache2 | |
install_apache() { | |
# | |
# Install Apache2 | |
sudo apt-get -yq install apache2 | |
# | |
# Enable apache modules | |
sudo a2enmod headers | |
sudo a2enmod rewrite | |
sudo awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf > tmp.conf && mv tmp.conf /etc/apache2/apache2.conf | |
# | |
# Restart apache2 | |
# | |
sudo service apache2 restart | |
# | |
# Empty the webroot | |
if [ -f /var/www/html/index.html ] ; then | |
sudo rm /var/www/html/index.html | |
fi | |
} | |
# Install PHP | |
install_php() { | |
# | |
# Import distibution variables | |
. /etc/lsb-release | |
# | |
# Is PHP5? | |
if [ $DISTRIB_RELEASE = "12.04" ] || [ $DISTRIB_RELEASE = "14.04" ] || [ $DISTRIB_RELEASE = "15.04" ]; then | |
phpver="5" | |
fi | |
# | |
# Is PHP7? | |
if [ $DISTRIB_RELEASE = "16.04" ] || [ $DISTRIB_RELEASE = "16.10" ] || [ $DISTRIB_RELEASE = "17.04" ] || [ $DISTRIB_RELEASE = "17.10" ]; then | |
phpver="7" | |
fi | |
# | |
# Install PHP5 | |
if [ $phpver = "5" ]; then | |
# | |
echo "Installing PHP5.5.9" | |
sudo apt-get -yq install php5 php5-cli | |
sudo apt-get -yq install php5-{curl,gd,mcrypt,json,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php5 | |
# | |
# enable mods | |
sudo php5enmod mcrypt | |
fi | |
# | |
# Install PHP7 | |
if [ $phpver = "7" ]; then | |
# | |
echo "Installing PHP7.0" | |
sudo apt-get -yq install php7.0 php7.0-cli | |
sudo apt-get -yq install php7.0-{mbstring,curl,gd,mcrypt,json,xml,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php7.0 | |
fi | |
} | |
# Install composer (globally) | |
install_composer() { | |
# | |
# Install composer | |
sudo curl -sS https://getcomposer.org/installer | sudo php | |
sudo mv composer.phar /usr/local/bin/composer | |
sudo ln -s /usr/local/bin/composer /usr/bin/composer | |
} | |
# | |
install_nodejs() { | |
# | |
# Install nodejs | |
sudo apt -yq install nodejs nodejs-legacy npm | |
} | |
# Install MariaDB | |
install_mariadb() { | |
# | |
# Preset Selections | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $rootdbpass" | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $rootdbpass" | |
# | |
# Install | |
sudo apt-get -yqq install mariadb-server | |
sudo apt-get -yqq install libmariadbclient-dev | |
# | |
sudo service mysql start | |
# | |
# Set root user password | |
sudo mysql -u root -p$rootdbpass -e "CREATE DATABASE $dbname /*\!40100 DEFAULT CHARACTER SET utf8 */;" | |
sudo mysql -u root -p$rootdbpass -e "CREATE USER $dbuser@'%' IDENTIFIED BY '$dbpass';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'%';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '$rootdbpass';" | |
sudo mysql -u root -p$rootdbpass -e "FLUSH PRIVILEGES;" | |
# | |
sudo service mysql restart | |
} | |
# Install Application | |
#install_project() { | |
# # | |
# # Place install code here specific for the application | |
#} | |
# | |
# Main | |
# | |
main() { | |
# | |
write_info | |
# | |
setup_system | |
# | |
install_php | |
# | |
install_composer | |
# | |
install_apache | |
# | |
install_mariadb | |
# | |
#install_project | |
echo "Install finished." | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment