Posts for: #Development

Force Ssl Redirect With Apache2

The easiest way to permanently redirect (301), when dealing with apache2 that is, would be these three lines of code below:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The way this works in NGINX is just as easy:

server_name git.server.com; 
## Don't show the nginx version number, a security best practice 
server_tokens off; 
location / {
	return 301 https://git.server.com:443$request_uri;
}
Read more

Linux Installation of Zsh and Oh My Zsh

This can be done in two or three easy steps:

  1. sudo apt-get install zsh curl git
  2. sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  3. (optional, must be installed for the agnoster theme for example (see here)) sudo apt-get install fonts-powerline (echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699" to test)
Read more

Upgrading Mysql Dev Server

Currently

An old MySQL server (5.5.40) on an old Debian installation (3.2.63 with Kernel 3.2).

I want to either upgrade Debian to a newer version (maybe reinstallation?) or use Ubuntu 18.04 (currently being discussed in our team).

TODO

First of all, I’m going to dump all databases.

This is done by this script and on the machine directly but could also be run remotely.

#! /bin/bash

# naming timestamp 
TIMESTAMP=$(date +"%F")

# the output directory
BACKUP_DIR="~/db_dumps"

# username and password for mysql connection and mysqldump
MYSQL_USER="user"
MYSQL_PASSWORD="password"

# get the binaries
MYSQL=$(which mysql)
MYSQLDUMP=$(which mysqldump)

# create output dir ifnexists 
mkdir -p "$BACKUP_DIR"
 
# get all dbs
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
 
# iteration with folder and file creation
for db in $databases; do
	echo "dumping $db"
	$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db > "$BACKUP_DIR/$db-$TIMESTAMP.sql"
done

# a spinner while waiting
spin()
{
  spinner="/|\\-/|\\-"
  while :
  do
    for i in `seq 0 7`
    do
      echo -n "${spinner:$i:1}"
      echo -en "\010"
      sleep 1
    done
  done
}

# if gzip parameter is given, gzip all files afterwards
while [[ $# -gt 0 ]] && [[ ."$1" = .--* ]] ;
do
	spin &
	SPIN_PID=$!
	trap "kill -9 $SPIN_PID" `seq 0 15`

    opt="$1";
    shift;
	case "$opt" in
			"--gzip")
				echo "gzipping"
				for file in $BACKUP_DIR/*.sql; do
					gzip $file
				done
				;;
			"--zip")
				echo "zipping"
				for file in $BACKUP_DIR/*.sql; do
					zip -q $file.zip $file
					rm $file
				done
				;;
			"--tar")
				echo "creating tarball"
				for file in $BACKUP_DIR/*.sql; do
					tar -cvf $file.tar $file
					rm $file
				done
				;;
			"--targz")
				echo "creating tarball and gzipping"
				for file in $BACKUP_DIR/*.sql; do
					tar -czvf $file.tar.gz $file
					rm $file
				done
				;;
			*)
				;;
		esac
done

echo "done"
exit 0

And then I’m importing all dumps to a new server, which might not be set up yet.

Read more