Skip to content

Instantly share code, notes, and snippets.

@slogsdon
Last active April 14, 2024 19:07
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slogsdon/c0f6736f45f578e9e32f to your computer and use it in GitHub Desktop.
Save slogsdon/c0f6736f45f578e9e32f to your computer and use it in GitHub Desktop.
Simple Wordpress cluster backed by MySQL and a Redis object cache, all behind HAProxy
# Main container hosting Wordpress
#
# Can be scaled with `docker-compose scale web=n`
# to spawn `n` Wordpress nodes. A restart
# (`docker-compose restart`) may be required for
# scaled nodes to be added to the HAProxy
# node's configuration.
web:
build: .
command: php -S 0.0.0.0:8000 -t /code
expose:
- 8000
links:
- db
- redis
volumes:
- .:/code
# HAProxy container
haproxy:
image: tutum/haproxy
ports:
- "8000:80"
- "443:443"
links:
- web
environment:
BACKEND_PORT: 8000
# MySQL container
db:
image: orchardup/mysql
environment:
MYSQL_DATABASE: wordpress
# Redis container
redis:
image: redis
# Basic setup to copy Wordpress files,
# expected to be at '.', into the image
FROM orchardup/php5
ADD . /code
<?php
// Allows Wordpress permalinks to work
// behind the built-in PHP HTTP server
$root = $_SERVER['DOCUMENT_ROOT'];
chdir($root);
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
set_include_path(get_include_path().':'.__DIR__);
if(file_exists($root.$path))
{
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
$path = rtrim($path,'/').'/index.php';
if(strpos($path,'.php') === false) return false;
else {
chdir(dirname($root.$path));
require_once $root.$path;
}
}else include_once 'index.php';
<?php
// MariaDB settings
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', "db:3306");
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
$table_prefix = 'wp_';
// Redis settings
// only need to override the default host
//
// Works with https://wordpress.org/plugins/redis-cache/,
// not sure about others/
define('WP_REDIS_HOST', 'redis');
// Use your keys/salts
define('AUTH_KEY', '...');
define('SECURE_AUTH_KEY', '...');
define('LOGGED_IN_KEY', '...');
define('NONCE_KEY', '...');
define('AUTH_SALT', '...');
define('SECURE_AUTH_SALT', '...');
define('LOGGED_IN_SALT', '...');
define('NONCE_SALT', '...');
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment