Skip to content

Instantly share code, notes, and snippets.

@jakeydevs
Last active May 11, 2019 14:06
Show Gist options
  • Save jakeydevs/bd9189667009f277190134752bedc14c to your computer and use it in GitHub Desktop.
Save jakeydevs/bd9189667009f277190134752bedc14c to your computer and use it in GitHub Desktop.
DigitalOcean 18.06 - Laravel Ready Script
#! /bin/bash
# This script will take a default DigitalOcean droplet and
# install and configure all software needed to get an app
# running on it quickly.
#
# @author @JakeLPrice
# @created 11 May 2019
# 0. Update apt-get
sudo apt-get update > /dev/null 2>&1
# 1. Add other PHP Packages for Laravel
echo "$(tput setaf 2)Adding PHP packages ...$(tput sgr 0)"
sudo apt-get install php7.2-curl php7.2-xml php7.2-zip php7.2-gd php7.2-mysql php7.2-mbstring -y > /dev/null 2>&1
# 2. Check if composer is installed
command -v composer >/dev/null 2>&1 || {
# It is not - install
echo "$(tput setaf 2)Composer not installed. Installing ...$(tput sgr 0)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php > /dev/null 2>&1
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
}
# 3. turn on mod_rewrite
echo "$(tput setaf 2)Making sure Rewrite is on ...$(tput sgr 0)"
a2enmod rewrite > /dev/null 2>&1
# 4. Configure MYSQL app user
NEWPASS="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
mysql -e "CREATE USER 'app'@'localhost' IDENTIFIED BY '${NEWPASS}';"
mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'app'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"
# 5. Restart Apache
echo "$(tput setaf 2)Restarting APACHE ...$(tput sgr 0)"
service apache2 restart
# 6. Done
echo "$(tput setaf 2)New MYSQL user: app $(tput sgr 0)"
echo "$(tput setaf 2)New MYSQL password: '${NEWPASS}' $(tput sgr 0)"
echo "$(tput setaf 2)Completed! - PHP version will be printed below:$(tput sgr 0)"
php -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment