Skip to content

Instantly share code, notes, and snippets.

View afiqiqmal's full-sized avatar
👻
I may be slow to respond.

Hafiq afiqiqmal

👻
I may be slow to respond.
View GitHub Profile
@afiqiqmal
afiqiqmal / default.conf
Last active March 30, 2020 02:02
NGINX Laravel Config
server {
listen 80;
listen [::]:80;
proxy_http_version 1.1;
proxy_set_header Connection "";
root /PROJECT_PATH/public;
index index.html index.htm index.php index.nginx-debian.html;
@afiqiqmal
afiqiqmal / ubuntu_server_setup_notes.txt
Created March 25, 2020 01:37
Ubuntu Server Setup for Laravel
Command Document
First thing first fresh server add new user
# adduser administrator
# usermod -aG sudo administrator
Install NGINX
# sudo apt install nginx
# sudo ufw allow 'Nginx HTTP'
@afiqiqmal
afiqiqmal / permission.sh
Last active March 25, 2020 03:55
Laravel File Permission
composer install
# Change folder directory permission
sudo find project_folder -type f -exec chmod 664 {} \;
sudo find project_folder -type d -exec chmod 775 {} \;
# Change laravel directory permission
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
@afiqiqmal
afiqiqmal / pre-commit
Last active March 24, 2020 04:03
Pre commit Versioning
#!/bin/sh
if ! type "jq" > /dev/null; then
echo "Please install jq command to commit. run command 'brew install jq'"
exit 1
fi
currentVersion=$(jq .version .version.json | bc -l)
currentBuildNumber=$(jq .build_number .version.json | bc -l)
@afiqiqmal
afiqiqmal / count_access_log_nginx.sh
Last active July 23, 2021 15:38
Sort Nginx Access Log Per Hour
#count total request
awk -F[:\ ] '{count[$5]++}; $12 == 200 { hour[$5]++} END { for (i in hour) print i, count[i] }' /var/log/nginx/access.log | sort
#count Ip address
cat /var/log/nginx/access.log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20
zcat /var/log/nginx/access.log.2.gz | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -50
# Deny IP
ufw insert 1 deny from 14.192.209.123 to any
@afiqiqmal
afiqiqmal / update.php
Created January 3, 2020 08:58 — forked from GianpaMX/update.php
Automatically updating a hosts file for dynamic dns
<?php
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
$redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location: $redirect");
}
class Host {
private $ip;
private $hosts;
@afiqiqmal
afiqiqmal / nginx.conf
Created December 22, 2019 05:21 — forked from weapp/nginx.conf
Return common errors as json in Nginx
error_page 500 /500.html;
location /500.html{
return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
}
error_page 502 /502.html;
location /502.html{
return 502 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
@afiqiqmal
afiqiqmal / Dockerfile
Last active November 9, 2019 15:24
Dockerfile for laravel application
FROM webdevops/php-nginx:7.2
ARG WHAT_ENVIRONMENT=local
ARG PROJECT_FOLDER_NAME=laravel_app
LABEL maintainer=hafiq
LABEL email=hafiq@terato.com
#####################################
# Software Installation #
@afiqiqmal
afiqiqmal / 2019_11_03_081136_alter_all_table_id.php
Last active July 28, 2023 21:57
Migrate bigIncrements to increments with foreign key attached
<?php
/**
* Created by PhpStorm.
* User: hafiq
* Date: 03/11/2019
* Time: 11:36 PM
*/
use Illuminate\Support\Facades\Schema;
@afiqiqmal
afiqiqmal / APNS.php
Last active August 11, 2019 04:10
Sample of APNS
<?php
namespace App\PushNotification;
class Apns
{
static function sendPush($deviceToken, $message, $type = '', $contentId = -1) {
// check if is not empty string
if (!isset($deviceToken) || strlen($deviceToken) == 0) {