Skip to content

Instantly share code, notes, and snippets.

View hoai's full-sized avatar

hoai hoai

View GitHub Profile
@hoai
hoai / Dockerfile - PHP and Apache
Created December 5, 2023 02:26 — forked from LouisBertin/Dockerfile - PHP and Apache
Production ready Dockerfile for PHP and Apache
FROM php:7.4-apache
WORKDIR /app
# update & upgrade
RUN apt-get update -y && apt-get upgrade -y && apt-get install apt-utils -y
# Php extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions intl bcmath gd pdo_mysql opcache uuid exif pcntl zip
@hoai
hoai / nginx-traefik-v2-docker-compose.yml
Created November 26, 2023 09:24 — forked from ismailyenigul/nginx-traefik-v2-docker-compose.yml
nginx and traefik v2 deployment with docker-compose
1. create a network with docker network create NETWORKNAME
2. Create letsencrypt directory for acme.json ie /docker/letsencrypt directory or somewhere else mkdir -p /docker/letsencrypt
3. I configured http -> https redirect
# cat docker-compose.yml
version: '3.3'
services:
traefik2:
image: traefik
@hoai
hoai / gist:06a098f161217f185eb3796b203e28d3
Created November 15, 2023 07:26 — forked from jaxbot/gist:5748513
Block nginx from serving .git directories
location ~ /\.git {
deny all;
}
# or, all . directories/files in general (including .htaccess, etc)
location ~ /\. {
deny all;
}
@hoai
hoai / s3_janitor.sh
Created November 8, 2023 02:51 — forked from eduardogspereira/s3_janitor.sh
Delete files from S3 that are older than X days.
#!/bin/bash
# You need to uncomment two lines for the script work.
# Please check the logic before use it.
main () {
#aws s3 ls $BUCKETNAME | grep -v ' PRE ' | grep -v ' 0 ' > data.txt
UNIXDAYS=$(date -d "$DAYS days ago" +%s)
while read LINE
do
@hoai
hoai / cmd.sh
Created November 7, 2023 07:23 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@hoai
hoai / cancel-aws-batch-jobs.sh
Created October 9, 2023 04:13
Cancel All AWS Batchs Jobs to run
#! /bin/bash
for i in $(aws --profile [PROFILE] --region [REGION] batch list-jobs --job-queue [QUEUE] --job-status runnable --output text --max-items 10000 --query jobSummaryList[*].[jobId])
do
echo "Cancel Job: $i"
aws --profile [PROFILE] --region [REGION] batch cancel-job --job-id $i --reason "Cancelling job."
#echo "Job $i canceled"
done
@hoai
hoai / kill-all-php-fpm.sh
Created October 9, 2023 03:48 — forked from bmichalski/kill-all-php-fpm.sh
Kill all php-fpm processes
sudo kill -9 `sudo ps -ef | grep php-fpm | grep -v grep | awk '{print $2}'`
@hoai
hoai / connectionlog.php
Created October 4, 2023 04:28 — forked from jwne/connectionlog.php
Log connecting clients' IP, port, user agent, and HTTP referer with a timestamp of the connection. MySQL storage preferred.
<?php
// For now file storage requires that the file specified is created already and chmodded to allow writing.
/**
* Connection info logging script created by Xeru
*
* Website: https://xeru.me
* Twitter: https://twitter.com/Xeru_
* GitHub: https://github.com/exec
@hoai
hoai / Nginx Docker and PHP-FPM.md
Created August 24, 2023 06:04 — forked from selfinvoking/Nginx Docker and PHP-FPM.md
Easily run different PHP versions with nginx, using Docker

Easily run different PHP versions with nginx, using Docker

Using this method will allow you to develop with any version of PHP you require without having to install it or worry about uninstalling other versions.

Method

If you are switching versions you will first want to stop and remove any existing php-fpm docker instance.

docker stop php

docker rm php

@hoai
hoai / sqlsrv_test.php
Created July 24, 2023 03:05 — forked from MCF/sqlsrv_test.php
PDO sqlsrv PHP driver, connect and query SQL Server database - reduced test case.
<?php
$serverName = "sqlserver.example.com";
$database = "myDbName";
$uid = 'sqlserver_username';
$pwd = 'password';
try {
$conn = new PDO(
"sqlsrv:server=$serverName;Database=$database",
$uid,