Skip to content

Instantly share code, notes, and snippets.

View mkacz's full-sized avatar

Milo Kaczorowski mkacz

View GitHub Profile
@mkacz
mkacz / gist:cb7685de5b60eba73dfe4d050c39577b
Created February 19, 2018 12:02
mysql db & user quickstart
CREATE USER 'user'@'localhost' IDENTIFIED BY 'passwd';
CREATE DATABASE db_name;
GRANT ALL PRIVILEGES ON db_name.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
# Fix permission to files
find . -type f -exec chmod 0644 {} \;
find . -type d -exec chmod 0755 {} \;
# Fix perms to all files excluding .git repo directory
find . -type f -prune -o -name .git -exec chmod 0644 {} \;
find . -type d -prune -o -name .git -exec chmod 0775 {} \;
# add all: Changes not staged for commit
git ls-files --modified | xargs git add
lsof -iTCP -sTCP:LISTEN
cp -r app/views app/views-backup
cd app/views
for x in `find . -iname \*erb`; do erb2slim $x ; done
rm -f `find . -iname \*erb`
# Recommended first steps on fresh server:
# https://gist.github.com/mkacz/3c3be134972a2a6688b4c77d8c86740b
# Install nginx
sudo add-apt-repository ppa:nginx/stable
sudo apt update
sudo apt install -y nginx
# Install postgresql
echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Upgrade
apt update -y
apt upgrade
# Inspect & remove what's not needed:
w
cat /etc/passwd
netstat -nlp
dpkg -l
ps -Af
# Creating dump # (If dump for Heroku add: --no-acl --no-owner)
pg_dump -h localhost -U db_user db_name > dump_file.sql
# Restoring dump
sudo su postgres
createuser -P --interactive db_owner
createdb db_name --owner=db_owner --encoding=utf8 -l en_US.utf8 -T template0
# Optional if dump has been done withoud --no-acl --no-owner opts
# Install certbot on Ubuntu
# https://certbot.eff.org/#ubuntuxenial-nginx
# https://certbot.eff.org/docs/using.html#getting-certificates-and-choosing-plugins
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install certbot python-certbot-nginx
# vhost definition must be placed in /etc/nginx/sites-enabled/domain.tld
@mkacz
mkacz / rbenv quickstart
Last active May 11, 2018 11:11
rbenv quickstart for ruby on rails
# Older than 18.04-lts
# apt install gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
apt install gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
logout