Skip to content

Instantly share code, notes, and snippets.

@fionera
Created August 1, 2025 20:19
Show Gist options
  • Save fionera/a1e9831e84fb937859af844551ee65cc to your computer and use it in GitHub Desktop.
Save fionera/a1e9831e84fb937859af844551ee65cc to your computer and use it in GitHub Desktop.
Configless wordpress
```
<?php
define('DB_NAME', get_current_user());
define('DB_USER', get_current_user());
define('DB_PASSWORD', '');
define('DB_HOST', '/run/mysqld/mysqld.sock');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
$table_prefix = 'wp_';
try {
$secret_keys = ['AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => ''];
if (file_exists(ABSPATH . '.keys.json')) {
$secret_keys = json_decode(file_get_contents(ABSPATH . '.keys.json'), true, 2, JSON_THROW_ON_ERROR);
} else {
array_walk($secret_keys, static function (&$value) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
$max = strlen($chars) - 1;
$value = '';
for ($j = 0; $j < 64; $j++) {
$value .= $chars[random_int(0, $max)];
}
});
file_put_contents(ABSPATH . '.keys.json', json_encode($secret_keys, JSON_THROW_ON_ERROR));
}
array_map(static fn($k, $v) => define($k, $v), array_keys($secret_keys), array_values($secret_keys));
unset($secret_keys);
} catch (Error|Exception $e) {
error_log($e);
echo "Fatal error. Please contact Administrator.";
die();
}
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('DISABLE_WP_CRON', true);
require_once ABSPATH . 'wp-settings.php';
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment