Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / mysql
Created April 22, 2020 17:22
Monit: MariaDB and MySQL
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql with timeout 15 seconds for 3 times within 4 cycles then restart
if failed unixsocket /var/run/mysqld/mysqld.sock protocol mysql for 3 times within 4 cycles then restart
if 5 restarts with 5 cycles then timeout
depend mysql_bin
depend mysql_rc
@eksiscloud
eksiscloud / functions.php
Last active September 4, 2023 15:23
Delete coupons of Woocommerce when those are expired
/**
* add this in the functions.php of theme/child theme/snippets plugin
* Schedule the daily event if necessary.
*/
function schedule_delete_expired_coupons() {
if ( ! wp_next_scheduled( 'delete_expired_coupons' ) ) {
wp_schedule_event( time(), 'daily', 'delete_expired_coupons' );
}
}
add_action( 'init', 'schedule_delete_expired_coupons' );
@eksiscloud
eksiscloud / example.com.conf
Created February 6, 2020 12:34
Tighter Wordpress at Nginx and with Fail2ban
## in the server block
#
# note: if you have posts with title matching these, turn them off or fine-tune
# them to exclude those
## Block SQL injections
location ~* union.*select.*\( {
access_log /var/log/nginx/blocked.log blocked;
deny all;
}
@eksiscloud
eksiscloud / functions.php
Created June 6, 2020 15:28
Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
# Check: https://onexa.nl/wordpress/toolbar-link-redis-object-cache/
/**
* Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
*
* @author Hiranthi Herlaar, onexa.nl
*
* @var $wp_admin_bar > https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
**/
function redis_add_toolbar_link( $wp_admin_bar )
{
@eksiscloud
eksiscloud / cachewarmer.sh
Created May 22, 2021 07:43
Cache Warmer using sitemap
#!/bin/bash
# CACHE WARMER script for XML Sitemaps with MULTIPLE SUB-SITEMAPS:
# from: https://gist.github.com/JPustkuchen/f185bee60c5a36211cdf6f1c8f6deebe
# chmod u+x
DOMAIN='https://www.xyz.com'
wget -q $DOMAIN/sitemap.xml --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read subsite;
do
echo --- Reading sub-sitemap: $subsite: ---
wget -q $subsite --no-cache -O - | egrep -o "$DOMAIN[^<]+" | while read line;
do
@eksiscloud
eksiscloud / wp-plugins.sh
Last active March 19, 2021 12:06
WP CLI + Bash: Batch installer of Wordpress plugins
#!/usr/bin/env bash
## WordPress Plugin Installer using BASH and WP-CLI
# Make executable: chmod u+x wp-plugins
# remember change WPPATH
# array of plugin slugs to install
WPPLUGINS=(
advanced-database-cleaner basepress categorytinymce classic-editor code-snippets change-last-modified-date disqus-comment-system
@eksiscloud
eksiscloud / functions.php
Created October 28, 2019 09:13
Wordpress: Use Amazon SES with PHPMailer
add_action( 'phpmailer_init', 'set_phpmailer_details' );
function set_phpmailer_details( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'SMTP_endpoint'; //Amazon SES SMTP endpoint for your region
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = 'Amazon_SES_USERNAME';
$phpmailer->Password = 'Amazon_SES_PASSWORD';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->From = get_option('admin_email'); //your verified email address
@eksiscloud
eksiscloud / wget
Last active March 19, 2021 12:03
Warm up of reverse proxy like Varnish using wget
wget --spider -o wget.log -e robots=off -r -l 5 -p -S -T3 --header="X-Bypass-Cache: 1" -H --domains=example.tld --show-progress www.example.tld
# Options explained
# --spider: Crawl the site
# -o wget.log: Keep the log
# -e robots=off: Ignore robots.txt
# -r: specify recursive download
# -l 5: Depth to search. I.e 1 means 'crawl the homepages'. 2 means 'crawl the homepage and all pages it links to'...
# -p: get all images, etc. needed to display HTML page
# -S: print server response (to the log)
@eksiscloud
eksiscloud / matomo.conf
Created January 27, 2020 17:22
Basic virtual host for Matomo in Nginx
server {
listen [::]:80; # remove this if you don't want Matomo to be reachable from IPv6
listen 80;
server_name analytics.example.com;
access_log /var/log/nginx/matomo.access.log;
error_log /var/log/nginx/matomo.error.log;
root /var/www/matomo/;
@eksiscloud
eksiscloud / redis.conf
Last active March 19, 2021 11:59
Simplified /etc/redis/redis.conf
bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
# unixsocket /var/run/redis/redis-server.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 300
daemonize yes