Skip to content

Instantly share code, notes, and snippets.

@treckstar
Created October 2, 2022 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treckstar/b41128dc0420ffb7501f132d5c68ffbf to your computer and use it in GitHub Desktop.
Save treckstar/b41128dc0420ffb7501f132d5c68ffbf to your computer and use it in GitHub Desktop.
Ubuntu 18.04 - 20.04
#!/bin/bash
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
#
# These are just some functions to add into the ~/.bashrc file
# Modified print_r command to output color without installing any themes
# Normally around line #118 these can be placed. I always put them at the end of file.
# You must restart the terminal after updating the ~/.bashrc file
cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m" # <-- [0 means not bold
YELLOW="\033[1;33m" # <-- [1 means bold
CYAN="\033[1;36m"
# ... Add more colors if you like
NC="\033[0m" # No Color
# printf "${(P)1}${2} ${NC}\n" # <-- zsh
printf "${!1}${2} ${NC}\n" # <-- bash
}
# Function to fix all Laravel 5.8 - 9.x permissions
# Just cd into the docroot and run `laraperms` and it will set all the permissions
laraperms(){
cecho "CYAN" "LArAPErMS.. setting perms in your CWD"
if [ -f ./artisan ]; then
cecho "GREEN" "Laravel has been found! Settings permissions!"
sudo chown -R $USER:www-data .
sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
else
cecho "YELLOW" "This folder does not have Laravel installed... aborting.."
fi
}
# Easily restart all services with one command
# Obviously this can be modified to fit your services
srvcs(){
cecho "CYAN" "Restarting all the important services..."
sudo service ssh restart
cecho "GREEN" "SSH has been restarted."
sudo service nginx stop
cecho "YELLOW" "nginx has been stopped. o.o"
sudo service php7.3-fpm stop
cecho "YELLOW" "php7.3-fpm has been stopped. o.o"
sudo service php7.4-fpm stop
cecho "YELLOW" "php7.4-fpm has been stopped. o.o"
sudo service php8.1-fpm stop
cecho "YELLOW" "php8.1-fpm has been stopped. o.o"
sudo service mysql stop
cecho "YELLOW" "mysql has been stopped. o.o"
sudo service mysql start
cecho "GREEN" "mysql has been started."
sudo service php8.1-fpm start
cecho "GREEN" "php8.1-fpm has been started."
sudo service php7.4-fpm start
cecho "GREEN" "php7.4-fpm has been started."
sudo service php7.3-fpm start
cecho "GREEN" "php7.3-fpm has been started."
sudo service nginx start
cecho "GREEN" "nginx has been started."
sudo nginx -t
cecho "GREEN" "nginx tested config."
}
# Aias to update the current version of PHP being used.
# I always forget this command so I made it work as `updatephp`
alias updatephp='sudo update-alternatives --config php'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment