Last active
April 14, 2024 19:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic setup to copy Wordpress files, | |
# expected to be at '.', into the image | |
FROM orchardup/php5 | |
ADD . /code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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