Skip to content

Instantly share code, notes, and snippets.

@hoahovan
Last active November 26, 2019 07:35
Show Gist options
  • Select an option

  • Save hoahovan/a647893204195da91e910732bdec8e5a to your computer and use it in GitHub Desktop.

Select an option

Save hoahovan/a647893204195da91e910732bdec8e5a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if script is being run by root
if [[ $EUID -ne 0 ]]; then
printf "This script must be run as root!\n"
exit 1
fi
DIVIDER="\n***************************************\n\n"
# Set the hostname
printf $DIVIDER
printf "HOSTNAME\n"
printf "Pick a hostname that identify this server.\nRecommended: use the main domain, e.g. example.com\n"
while true; do
read -p "Hostname: " host
case $host in
"" ) printf "Hostname may not be left blank\n";;
* ) break;;
esac
done
echo "$host" > /etc/hostname
hostname -F /etc/hostname
printf "127.2.1 $host\n::1 $host\n" >> /etc/hosts;
# Set the time zone
printf $DIVIDER
printf "TIME ZONE\n"
printf "Please select the correct time zone. e.g. US > Eastern Time\n"
read -p "Please ENTER to continue "
dpkg-reconfigure tzdata
# Install and update software
printf $DIVIDER
printf "INSTALL AND UPDATE SOFTWARE\n"
printf "Now the script will update Ubuntu and install all the necessary software.\n"
printf " * You will be prompted to enter the password for the MySQL root user\n"
read -p "Please ENTER to continue "
sudo apt -y update
sudo apt -y install apache2 apache2-doc
sudo apt -y install mysql-server
sudo apt -y install php7.2 libapache2-mod-php7.2 php-mysql
sudo apt -y install php-curl php-json php-cgi mcrypt imagemagick
sudo apt -y install php7.2-common php7.2-gd php7.2-imap php7.2-mysql php7.2-cli php7.2-cgi php-pear php-auth php-mcrypt php-imagick php7.2-curl php7.2-mbstring php7.2-bcmath php7.2-xml php7.2-soap php7.2-opcache php7.2-intl php-apcu php-mail php-mail-mime php7.2-memcached php-all-dev php7.2-dev libapache2-mod-php7.2
sudo ufw app info "Apache Full"
sudo ufw allow in "Apache Full"
sudo systemctl restart apache2
# Setup database
printf "Setup databases and users\n"
while true; do
read -p "Enter password for MySQL root: " mysqlrootpsw
case $mysqlrootpsw in
"" ) printf "Password may not be left blank\n";;
* ) break;;
esac
done
printf "\nPlease set name for databases, users and passwords\n"
while true; do
read -p "Production database name (recommended: use domain without TLD, for mydomain.com use mydomain): " dbname
case $dbname in
"" ) printf "Database name may not be left blank\n";;
* ) break;;
esac
done
while true; do
read -p "Production database user (recommended: use same as database name, max 16 characters): " dbuser
case $dbuser in
"" ) printf "User name may not be left blank\n";;
* ) break;;
esac
done
while true; do
read -p "Production database password: " dbpass
case $dbpass in
"" ) printf "\nPassword may not be left blank\n";;
* ) break;;
esac
done
printf "Create database $dbname...\n"
mysql -u root -p$mysqlrootpsw -e "CREATE DATABASE $dbname;"
printf "Create user $dbuser...\n"
mysql -u root -p$mysqlrootpsw -e "CREATE USER '$dbuser'@localhost IDENTIFIED BY '$dbpass';"
printf "Grant $dbuser all privileges on $dbname...\n"
mysql -u root -p$mysqlrootpsw -e "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@localhost;"
printf "Restart MySQL...\n"
service mysql restart
# Set authorize
chown -R www-data:www-data /var/www
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment