Last active
March 12, 2019 19:26
-
-
Save danrichards/efa51c85e8746144b914 to your computer and use it in GitHub Desktop.
Productive .bashrc file for your BITNAMI LAMP server. (using with Amazon AMI-7679c91e)
This file contains hidden or 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
# ------------------------------------------------------------------ | |
# IF YOU EDIT THIS FILE OUTSIDE OF THE SERVER, BE SURE YOUR LINE | |
# ENDINGS ARE SET TO UNIX. SublimeText2 > View > Line Endings > Unix | |
# ------------------------------------------------------------------ | |
# Put .danrc into the same folder as your .bashrc file | |
# Typically, this is /home/username/ | |
# $ sudo nano /home/username/.bashrc | |
# Include in your .bashrc file | |
# source .danrc | |
# ----------------------------------------------------------------- | |
# ----------------------------------------------------------------- | |
# list whenever we change directory | |
# ----------------------------------------------------------------- | |
function cd { | |
builtin cd $@ && ls | |
} | |
# ------------------------------------------------------------------ | |
# aliases for kicking ass | |
# ------------------------------------------------------------------ | |
alias md="mkdir" | |
alias ll="ls -ltr" | |
alias cl="clear;ll" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias bashrc="sudo nano $HOME/.bashrc" | |
alias danrc="sudo nano $HOME/.danrc" | |
alias aliases="compgen -a" | |
alias commands="compgen -bc | grep " | |
alias home="cd /home/dan/" | |
# ---------------------------------------------------------------------- | |
# aliases to give perms to stuff | |
# ---------------------------------------------------------------------- | |
alias username="sudo chown -R username:bitnami " | |
alias bitnami="sudo chown -R bitnami:bitnami " | |
alias perm-pyro="sudo chmod -R 777 assets/cache;sudo chmod -R 777 system/cms/logs;sudo chmod -R 777 system/cms/cache;sudo chmod -R 777 system/cms/config;sudo chmod -R 777 uploads" | |
alias perm-laravel="sudo chmod -R 777 app/storage" | |
# ----------------------------------------------------------------------- | |
# aliases for the server | |
# ----------------------------------------------------------------------- | |
alias my.cnf="sudo nano /opt/bitnami/mysql/my.cnf" | |
alias php.ini="sudo nano /opt/bitnami/php/etc/php.ini" | |
alias httpd.conf="sudo nano /opt/bitnami/apache2/conf/httpd.conf" | |
alias vhosts="sudo nano /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf" | |
alias websites="cd /opt/bitnami/apache2/websites/username/" | |
alias sudoers="sudo nano /etc/sudoers.d/90-cloud-init-users" | |
alias restart-server="sudo /opt/bitnami/ctlscript.sh restart" | |
alias stop-server="sudo /opt/bitnami/ctlscript.sh stop" | |
alias start-server="sudo /opt/bitnami/ctlscript.sh start" | |
alias restart-apache="sudo /opt/bitnami/ctlscript.sh restart apache" | |
alias restart-mysql="sudo /opt/bitnami/ctlscript.sh restart mysql" | |
alias stop-apache="sudo /opt/bitnami/ctlscript.sh stop apache" | |
alias stop-mysql="sudo /opt/bitnami/ctlscript.sh stop mysql" | |
alias start-apache="sudo /opt/bitnami/ctlscript.sh start apache" | |
alias start-mysql="sudo /opt/bitnami/ctlscript.sh start mysql" | |
alias debug-server="cd /opt/bitnami/apache2/logs" | |
# --------------------------------------------------------------- | |
# vhost | |
# | |
# open a vhost file | |
# | |
# @param sitename (leave off the .conf) | |
# @note there is an alias called vhosts to edit httpd-vhosts.conf | |
# --------------------------------------------------------------- | |
function vhost { | |
cd /opt/bitnami/apache2/conf/extra/websites/ | |
sudo nano $1.conf | |
} | |
# ------------------------------------------------------------- | |
# vhost-up | |
# | |
# add a vhost to our server, creates a separate file and adds a | |
# include to our httpd-vhosts.conf | |
# | |
# @param sitename | |
# ------------------------------------------------------------- | |
function vhost-up { | |
sudo rm -f /opt/bitnami/apache2/conf/extra/websites/$1.conf | |
printf "# -----------------------------\n# http://$1\n# -----------------------------\n\n<VirtualHost *:80>\n ServerAdmin [email protected]\n DocumentRoot \"/opt/bitnami/apache2/websites/username/$1/public\"\n ServerName $1\n ServerAlias www.$1\n ErrorLog \"logs/$1-errors.log\"\n CustomLog \"logs/$1-access.log\" combined\n</VirtualHost>" | sudo tee /opt/bitnami/apache2/conf/extra/websites/$1.conf | |
echo "" | |
echo "" | |
echo "CREATED /opt/bitnami/apache2/conf/extra/websites/$1.conf" | |
sudo sh -c "printf \"\ninclude \"/opt/bitnami/apache2/conf/extra/websites/$1.conf\"\" >> /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf" | |
echo "" | |
echo "APPENDED include \"/opt/bitnami/apache2/conf/extra/websites/$1.conf\"" | |
echo "" | |
echo "RESTARTING APACHE, IF SYNTAX ERRORS ARE REPORTED, INVESTIGATE" | |
restart-apache | |
echo "" | |
echo "VHOST ONLINE, REGISTRAR'S ZONE FILE SHOULD POINT TO 54.174.34.100" | |
} | |
# ------------------------------------------------------- | |
# vhost-down | |
# | |
# take down a site vhost file, load the httpd-vhosts.conf | |
# file (to unreference manually) and restart the server | |
# | |
# @param sitename | |
# ------------------------------------------------------- | |
function vhost-down { | |
# vhosts are keep in separate files, delete it | |
sudo rm /opt/bitnami/apache2/conf/extra/websites/$1.conf | |
echo "" | |
echo "DELETED /opt/bitnami/apache2/conf/extra/websites/$1.conf" | |
# prompt the user and warn them they'll have to remove the reference | |
read -n 1 -r -p "Delete site reference yourself, press any key to continue..." | |
vhosts | |
# restart apache | |
echo "RESTARTING APACHE" | |
restart-apache | |
} | |
# ------------------------------------------------------ | |
# link-up | |
# | |
# create a symbolic link in our home folder to a website | |
# | |
# @param | |
# ------------------------------------------------------ | |
function link-up { | |
ln -s /opt/bitnami/apache2/websites/username/$1/ $1 | |
echo "LINK CREATED FOR WEBSITE DIRECTORY $1" | |
ls | |
} | |
# -------------------------------------------------------------- | |
# post-receive-up | |
# | |
# create a post-receive hook | |
# | |
# @param foldername (excluding the .git extension) | |
# -------------------------------------------------------------- | |
function post-receive-up { | |
touch /home/username/$1.git/hooks/post-receive | |
printf "#!/bin/sh\nGIT_WORK_TREE=/home/username/$1\nexport GIT_WORK_TREE\ngit checkout -f" >> /home/username/$1.git/hooks/post-receive | |
chmod -R 755 hooks/post-receive | |
} | |
# ----------------------------------------------------------------- | |
# gitty-up | |
# | |
# create a bare git repo in your users folder | |
# | |
# @param foldername (excluding .git extension) | |
# ----------------------------------------------------------------- | |
function gitty-up { | |
md /home/username/$1.git | |
cd /home/username/$1.git | |
git init --bare | |
# create a post-receive hook and take permission of the folder | |
post-receive-up $1 | |
username * | |
} | |
# ------------------------------------------------- | |
# web-down | |
# | |
# take down a website, provide feedback | |
# | |
# @param sitename | |
# ------------------------------------------------- | |
function web-down { | |
# remove folders and give feedback | |
sudo rm -r /opt/bitnami/apache2/websites/username/$1 | |
echo "DELETED /opt/bitnami/apache2/websites/username/$1 - FOLDER" | |
sudo rm -r /home/username/$1 | |
echo "DELETED /home/username/$1 - LINK" | |
sudo rm -r /home/username/$1.git | |
echo "DELETED /home/username/$1.git - GIT REPO" | |
echo "" | |
# remove the vhost and go home | |
vhost-down $1 | |
home | |
} | |
# ------------------------------------------------------ | |
# web-up | |
# | |
# put up a new website, git initialize it, vhost it | |
# | |
# @param sitename | |
# ------------------------------------------------------ | |
function web-up { | |
sudo mkdir -p /opt/bitnami/apache2/websites/username/$1/public | |
username /opt/bitnami/apache2/websites/username/$1 | |
echo "CREATED /opt/bitnami/apache2/websites/username/$1" | |
link-up $1 | |
# create a bare git repo | |
gitty-up $1 | |
# configure a new vhost | |
vhost-up $1 | |
} | |
# ----------------------------------------------------------- | |
# laravel-up | |
# | |
# web-up and pre-load it with laravel | |
# | |
# @param sitename | |
# @assumes - laravel boiler-plate located in | |
# /home/bitnami/templates/laravel4.tmp | |
# ----------------------------------------------------------- | |
function laravel-up { | |
# create a website | |
web-up $1 | |
# copy laravel to it | |
echo "COPYING LARAVEL, PLEASE WAIT..." | |
sudo cp -r /home/bitnami/templates/laravel4.tmp/* /opt/bitnami/apache2/websites/username/$1 | |
username /opt/bitnami/apache2/websites/username/$1 | |
echo "LARAVEL FINISHED COPYING TO $1" | |
cd /home/username/$1 | |
perm-laravel | |
echo "PERMISSIONS GRANTED TO LARAVEL STORAGE FOLDER" | |
#notify done | |
echo "LARAVEL-UP FINISHED" | |
} | |
# ---------------------------------------------------------- | |
# run home command on login | |
# ---------------------------------------------------------- | |
home |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment