HostForge upstream setup

This commit is contained in:
Gilbert Caro
2026-04-09 02:49:31 +08:00
parent b70c252e2c
commit 68a7ca8ca4
4 changed files with 250 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea

151
wp-config-hostforge.php Normal file
View File

@@ -0,0 +1,151 @@
<?php
/**
* HostForge platform settings.
*
* IMPORTANT:
* This file should be managed by HostForge provisioning.
* Site-specific customizations should stay in wp-config.php
* or in a separate user-managed file if you want to support that later.
*/
/**
* Helper to fetch environment values safely.
*
* getenv() is preferred because $_ENV may not always be populated
* depending on PHP configuration.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
if (!function_exists('hf_env')) {
function hf_env(string $key, $default = null)
{
$value = getenv($key);
if ($value !== false) {
return $value;
}
return $_ENV[$key] ?? $default;
}
}
/**
* Required database settings.
*/
define('DB_NAME', hf_env('DB_NAME', ''));
define('DB_USER', hf_env('DB_USER', ''));
define('DB_PASSWORD', hf_env('DB_PASSWORD', ''));
define('DB_HOST', hf_env('DB_HOST', '127.0.0.1'));
define('DB_CHARSET', hf_env('DB_CHARSET', 'utf8mb4'));
define('DB_COLLATE', hf_env('DB_COLLATE', ''));
/**
* Authentication keys and salts.
*/
define('AUTH_KEY', hf_env('AUTH_KEY', ''));
define('SECURE_AUTH_KEY', hf_env('SECURE_AUTH_KEY', ''));
define('LOGGED_IN_KEY', hf_env('LOGGED_IN_KEY', ''));
define('NONCE_KEY', hf_env('NONCE_KEY', ''));
define('AUTH_SALT', hf_env('AUTH_SALT', ''));
define('SECURE_AUTH_SALT', hf_env('SECURE_AUTH_SALT', ''));
define('LOGGED_IN_SALT', hf_env('LOGGED_IN_SALT', ''));
define('NONCE_SALT', hf_env('NONCE_SALT', ''));
/**
* HostForge metadata.
*/
define('HOSTFORGE_SITE_ID', hf_env('HOSTFORGE_SITE_ID', ''));
define('HOSTFORGE_SITE_UUID', hf_env('HOSTFORGE_SITE_UUID', ''));
define('HOSTFORGE_ENVIRONMENT', hf_env('HOSTFORGE_ENVIRONMENT', 'production'));
define('HOSTFORGE_APP_TYPE', hf_env('HOSTFORGE_APP_TYPE', 'wordpress'));
/**
* WordPress environment type.
*
* Maps HostForge environment to WP_ENVIRONMENT_TYPE.
*/
if (!defined('WP_ENVIRONMENT_TYPE')) {
switch (HOSTFORGE_ENVIRONMENT) {
case 'production':
define('WP_ENVIRONMENT_TYPE', 'production');
break;
case 'staging':
define('WP_ENVIRONMENT_TYPE', 'staging');
break;
default:
define('WP_ENVIRONMENT_TYPE', 'development');
break;
}
}
/**
* Debug settings.
*/
if (!defined('WP_DEBUG')) {
define('WP_DEBUG', HOSTFORGE_ENVIRONMENT !== 'production');
}
if (!defined('WP_DEBUG_LOG')) {
define('WP_DEBUG_LOG', HOSTFORGE_ENVIRONMENT !== 'production');
}
if (!defined('WP_DEBUG_DISPLAY')) {
define('WP_DEBUG_DISPLAY', false);
}
@ini_set('display_errors', '0');
/**
* Detect scheme and set URLs dynamically.
*
* This is useful when the same codebase is used across temporary/staging domains.
*/
if (
!defined('WP_HOME') &&
!defined('WP_SITEURL') &&
isset($_SERVER['HTTP_HOST'])
) {
$scheme = 'http';
if (
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
(isset($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on')
) {
$scheme = 'https';
$_SERVER['HTTPS'] = 'on';
}
define('WP_HOME', $scheme . '://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', $scheme . '://' . $_SERVER['HTTP_HOST']);
}
/**
* Temporary directory.
*/
if (!defined('WP_TEMP_DIR')) {
define('WP_TEMP_DIR', sys_get_temp_dir());
}
/**
* Disable wp-cron if HostForge will run cron externally.
*/
if (!defined('DISABLE_WP_CRON')) {
define('DISABLE_WP_CRON', true);
}
/**
* Optional: disallow file modifications in non-development environments.
*
* This is useful if you want tighter control in staging/production.
*/
if (
!defined('DISALLOW_FILE_MODS') &&
in_array(HOSTFORGE_ENVIRONMENT, ['staging', 'production'], true)
) {
define('DISALLOW_FILE_MODS', true);
}

82
wp-config.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
/**
* Main WordPress configuration file.
*
* HostForge strategy:
* - If running under HostForge, load wp-config-hostforge.php
* - If running locally, allow wp-config-local.php
* - Otherwise fall back to manual defaults
*/
/**
* HostForge platform settings.
*
* We use HOSTFORGE_SITE_ID as the runtime marker that this site
* is being managed by HostForge.
*/
if (
file_exists(__DIR__ . '/wp-config-hostforge.php') &&
(
getenv('HOSTFORGE_SITE_ID') !== false ||
isset($_ENV['HOSTFORGE_SITE_ID'])
)
) {
require_once __DIR__ . '/wp-config-hostforge.php';
/**
* Local configuration information.
*
* Recommended for local development only.
* Make sure this file is gitignored.
*/
} elseif (file_exists(__DIR__ . '/wp-config-local.php')) {
require_once __DIR__ . '/wp-config-local.php';
/**
* Fallback configuration.
*
* Used only when not running under HostForge and no local config exists.
*/
} else {
define('DB_NAME', 'database_name');
define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', '127.0.0.1');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
}
/**
* WordPress database table prefix.
*/
$table_prefix = 'wp_';
/**
* Debug mode.
*
* Default false unless already defined by platform/local config.
*/
if (!defined('WP_DEBUG')) {
define('WP_DEBUG', false);
}
/**
* Absolute path to the WordPress directory.
*/
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . '/');
}
/**
* Sets up WordPress vars and included files.
*/
require_once ABSPATH . 'wp-settings.php';

View File

@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: HostForge Platform
*/
if (!defined('ABSPATH')) exit;
function hf_config($key, $default = null) {
return defined($key) ? constant($key) : $default;
}
add_action('init', function () {
if (hf_config('HOSTFORGE_ENABLE_TELEMETRY', false)) {
// later: send telemetry
}
});