Skip to content

Instantly share code, notes, and snippets.

@mwpastore
mwpastore / 00README.md
Last active July 18, 2024 08:32
Lightning Fast WordPress: Caddy+Varnish+PHP-FPM

README

This gist assumes you are migrating an existing site for www.example.com — ideally WordPress — to a new server — ideally Ubuntu Server 16.04 LTS — and wish to enable HTTP/2 (backwards compatibile with HTTP/1.1) with always-on HTTPS, caching, compression, and more. Although these instructions are geared towards WordPress, they should be trivially extensible to other PHP frameworks, other FastCGI backends, and even non-FastCGI backends (using proxy in lieu of fastcgi in the terminal Caddyfile stanza).

Quickstart: Use your own naked and canonical domain names instead of example.com and www.example.com and customize the Caddyfile and VCL provided in this gist to your preferences!

These instructions target Varnish Cache 4.1, PHP-FPM 7.0, and Caddy 0.10. (I'm using MariaDB 10.1 as well, but that's not relevant to this guide.)

@AustinGil
AustinGil / hero-section.php
Last active April 22, 2019 09:27
An example of my "Progressive Lazy Load" technique in WordPress using vanilla Javascript
<?php while (have_posts()) : the_post(); ?>
<?php
// Get the placeholder image and full size image URLs
if ( has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$full_size_image = wp_get_attachment_image_src( $image_id,'full', true);
$full_size_image_url = $full_size_image[0];
$placeholder_image = wp_get_attachment_image_src( $image_id,'thumbnail', true);
<?php
add_action( 'admin_menu', 'dat_add_admin_menu' );
add_action( 'admin_init', 'dat_settings_init' );
function dat_add_admin_menu( ) {
add_submenu_page( 'edit.php?post_type=dat_cpt', 'Automatic Divi Testimonials', 'Settings', 'manage_options', 'automatic_divi_testimonials', 'dat_options_page' );
}
@lukecav
lukecav / php.ini
Last active November 25, 2023 07:26
OPCache Options for WordPress
opcache.enable=1
opcache.memory_consumption=192
opcache.max_wasted_percentage=5
opcache.max_accelerated_files=7963
opcache.revalidate_freq=5
opcache.interned_strings_buffer=16
opcache.save_comments=1
opcache.load_comments=1
opcache.enable_file_override=0
opcache.fast_shutdown=1
@ryanjbonnell
ryanjbonnell / wp-config.php
Created March 12, 2014 15:51
WordPress Config: Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
// Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}