Skip to content

Instantly share code, notes, and snippets.

@jakeydevs
Last active May 21, 2019 08:00
Show Gist options
  • Save jakeydevs/9086783c681b32465c7d26b8ef4ee41b to your computer and use it in GitHub Desktop.
Save jakeydevs/9086783c681b32465c7d26b8ef4ee41b to your computer and use it in GitHub Desktop.
All in one - from DO to Laravel App
#! /bin/bash
# This script is my all in one Laravel dev enviroment for
# remote working. DO NOT USE ON LIVE SERVICES AS THERE COULD
# BE ISSUES
#
# It does:
# - Sets up PHP dependancies
# - Installs Composer
# - Creates MYSQL user
# - Installs NODEJS
# - Sorts out vhost
#
# @author @JakeLPrice
# @created 11 May 2019
# 0. Update apt-get
echo "$(tput setaf 2)Updating apt-get ...$(tput sgr 0)"
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. Install Nodejs (Instructions from https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04)
echo "$(tput setaf 2)Installing nodejs (v10.x) ...$(tput sgr 0)"
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh > /dev/null 2>&1
sudo apt-get install nodejs > /dev/null 2>&1
# 6. New apache vhost
echo "$(tput setaf 2)Adjusting apache VHOST file ...$(tput sgr 0)"
sudo rm /etc/apache2/sites-available/000-default.conf
cat << EOM > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/app/public
<Directory /var/www/app/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
EOM
# 7. Restart Apache
echo "$(tput setaf 2)Restarting APACHE ...$(tput sgr 0)"
service apache2 restart
# 8. Done
echo "$(tput setaf 2)✔ Completed $(tput sgr 0)"
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)PHP version will be printed below:$(tput sgr 0)"
php -v
echo "$(tput setaf 2)Node version will be printed below:$(tput sgr 0)"
nodejs -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment