Skip to content

Instantly share code, notes, and snippets.

@khoatran
khoatran / october.conf
Created June 26, 2017 14:14
Nginx fast cgi cache for OctoberCMS
#Set the path where the cache is stored; Set the zone name, totalsize (400m),and max life time(60m)
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=AICUNGXINH:400m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
#fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
server {
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
@khoatran
khoatran / rsync-remote.sh
Created September 29, 2017 07:11
Rsync from remote
rsync -avz --progress -e "ssh -i ssh_key" root@ip_of_the_remote:/folder/* /target-folder
@khoatran
khoatran / october-deployment.sh
Last active November 3, 2018 20:21
Bamboo deployment script
export DEPLOYMENT_FOLDER=/deployment-folder
export RELEASE_ROOT_FOLDER=$DEPLOYMENT_FOLDER/releases
export RELEASE_FOLDER=$DEPLOYMENT_FOLDER/releases/intermediate
cd $DEPLOYMENT_FOLDER/build
tar -xvf artifact.tar
rm -rf artifact.tar
cd $DEPLOYMENT_FOLDER
shopt -s dotglob
# Unzip and copy all files in artifact into the release folder
mkdir $RELEASE_FOLDER
@khoatran
khoatran / gist:75da6485ec690662e7f77e1952d89b5d
Created October 3, 2017 06:38
Fix Laravel mix strange issue spawn webpack.js ENOENT
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
@khoatran
khoatran / switch-php-version-ubuntu.sh
Created April 10, 2018 16:48
Switch between PHP version on Ubuntu
sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phar /usr/bin/phar7.1
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
sudo update-alternatives --set phpize /usr/bin/phpize7.1
sudo update-alternatives --set php-config /usr/bin/php-config7.1
@khoatran
khoatran / ModelNeedToValidate.php
Created January 2, 2018 07:49
OctoberCMS model validation
<?php
use Carbon\Carbon;
use Model;
use Validator;
/**
* Model
*/
class WorkingSchedule extends Model
{
@khoatran
khoatran / laravel-echo-fix-sqlite3.sh
Created October 3, 2017 07:47
Fix Cannot find module node_sqlite3.node when running Laravel Echo Server
cd /usr/local/lib/node_modules/laravel-echo-server/
npm install sqlite3 --save
@khoatran
khoatran / upgrade-node.sh
Created October 3, 2017 06:40
Upgrade nodejs
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<version>/bin/node /usr/bin/node
sudo ln -sf /usr/local/n/versions/node/<version>/bin/npm /usr/local/bin/npm
@khoatran
khoatran / rsync-options.sh
Created September 29, 2017 07:25
Rsync with options
#sync allows deleting files in target folder if the files in the source folder are deleted
rsync -rtvu --delete source_folder/ destination_folder/
#Compressing the files while transferring them
rsync -rtvz source_folder/ destination_folder/
#Transferring files between two remote systems
rsync -rtvz source_folder/ user@domain:/path/to/destination_folder/
rsync -rtvz source_folder/ user@xxx.xxx.xxx.xxx:/path/to/destination_folder/
rsync -rtvz source_folder/ server_name:/path/to/destination_folder/
@khoatran
khoatran / fix-short-ssh-timeout.sh
Created June 2, 2017 04:50
Fix the issue short SSH timeout on Linux server
It helps to add ClientAliveInterval of 60 mins into SSH config
sudo echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
#Then, restart SSH
#Below is the command to restart ssh on Ubuntu based
sudo service ssh restart
#Other Linux distribution
sudo service sshd restart