Skip to content

Instantly share code, notes, and snippets.

@Grendel7
Grendel7 / testmail.php
Last active July 14, 2018 10:26
Simple script to test PHP mail is working
<?php
$sender = 'from@example.com';
$recipient = 'to@example.com';
$subject = "PHP Mail Test Message";
$message = "PHP Mail Test Message";
$headers = [
'From: ' . $sender,
'Sender: ' . $sender,
];
@Grendel7
Grendel7 / lxc-salt-minion.sh
Created September 17, 2017 20:42
Install salt-minion to an LXC container and configure it to respond to a SaltStack master on `saltmaster`.
lxc-attach -n $MY_MINION -- sh -c "apt-get update && apt-get install curl -y && curl -L https://bootstrap.saltstack.com | sh && sed -i -e 's/#master: salt/master: saltmaster/g' /etc/salt/minion && systemctl restart salt-minion"
@Grendel7
Grendel7 / lxc-saltmaster.conf
Created September 17, 2017 20:44
Configuration sample for directory sharing with LXC for Saltstack local dev.
# Add the following line to /var/lib/lxc/saltmaster/config
lxc.mount.entry=/path/to/your/projects/saltstack srv none bind 0 0
@Grendel7
Grendel7 / lxc-create-saltmaster.sh
Created September 17, 2017 20:46
Create a Debian LXC container and install a SaltStack master to it
# Create the LXC container.
lxc-create -n saltmaster -t debian -- -r stretch
lxc-start -n saltmaster
# Install SaltStack on it.
lxc-attach -n saltmaster -- sh -c "apt-get update && apt-get install curl -y && curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com && sh bootstrap-salt.sh -M -N"
@Grendel7
Grendel7 / Vagrantfile
Last active April 6, 2018 08:15
Salt Development Vagrant stack
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
$master_bootstrap = <<SCRIPT
apt-get update
apt-get install -y apt-transport-https
wget -O - http://repo.saltstack.com/apt/debian/9/amd64/2017.7/SALTSTACK-GPG-KEY.pub | apt-key add -
@Grendel7
Grendel7 / file-counter.php
Last active August 28, 2022 10:45
PHP script to help identify high folders using many inodes
<?php
set_time_limit(0);
$directory = new RecursiveDirectoryIterator('../');
$counters = [];
foreach ($directory as $item) {
if (!is_dir($item)) {
{
"Version":"2008-10-17",
"Statement":[{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::example.com/*"]
@Grendel7
Grendel7 / aws-s3-single-bucket-permissions.json
Created April 23, 2018 17:01
AWS S3 permissions template for full access to a single bucket
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads"
],
"Resource": "arn:aws:s3:::BUCKETNAME",
@Grendel7
Grendel7 / nginx-multiple-php-apps-in-subdirs.conf
Created April 23, 2018 17:55
Example NGINX config file which loads different PHP-FPM apps from subdirectories
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /home/app/html/public;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
@Grendel7
Grendel7 / port-test.php
Last active November 22, 2023 11:36
Test connection to a hostname and port with PHP
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$domain = "smtp.gmail.com";
$port = 587;
if ($socket = stream_socket_client("tcp://{$domain}:{$port}", $errno, $errstr, 10)) {
echo "stream_socket_client: Connection to {$domain}:{$port} successful!<br>";