WP-CONFIG -PHP problem
-
Can someone assits me please in getting this script up and running?
$host = $HTTP_HOST; $parts = explode('.',$host); if ($parts[3] = '') { $domain = $parts[0]; } else { $domain = $parts[1]; } switch ($domain) { case '123.com'; $db = 'wordpress'; $user = 'root'; $password = ''; $hostname = 'localhost'; $table_prefix = '123_'; define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; break; case '345.com'; $db = 'wordpress'; $user = 'root'; $password = ''; $hostname = 'localhost'; $table_prefix = '345_'; define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; break; default; $db = 'wordpress'; $user = 'root'; $password = ''; $hostname = 'localhost'; $table_prefix = '345_'; define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; break; } define('DB_NAME', $db); define('DB_USER', $user); define('DB_PASSWORD', $password); define('DB_HOST', $hostname); define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); define ('WPLANG', $wplang);
-
Aside from some defines you’re missing, what is issue here?
Also, it’s good security practice to (1) NEVER use ‘root’ for your database user account and (2) use a different id/password for each database.
Thank you for your feedback …
Off course, I will never use root as user and an empty password … 🙂
Trying to test the script with XAMPP on my local development environment …The problem is, that the script always runs the “default” case only! 🙁
Here’s my complete wp-config:
<?php /** * The base configurations of the WordPress. * * This file has the following configurations: MySQL settings, Table Prefix, * Secret Keys, WordPress Language, and ABSPATH. You can find more information by * visiting {@link http://codex.ww.wp.xz.cn/Editing_wp-config.php Editing * wp-config.php} Codex page. You can get the MySQL settings from your web host. * * This file is used by the wp-config.php creation script during the * installation. You don't have to use the web site, you can just copy this file * to "wp-config.php" and fill in the values. * * @package WordPress */ /* Determining the domain - DO NOT EDIT */ $host = $HTTP_HOST; $parts = explode('.',$host); if ($parts[3] = '') { $domain = $parts[0]; } else { $domain = $parts[1]; } /* Domain - Edit below. Add more "cases" for each domain you want to have. Make sure each "case" has a "break; line at the end. */ switch ($domain) { case 'upi.loc'; // 'domain' in 'www.domain.com' $db = 'wordpress'; // the database for this domain $user = 'root'; // the username for this database $password = ''; // the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'wpmu_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) break; case 'german-lightning.loc'; // 'domain' in 'www.domain.com' $db = 'wordpress'; // the database for this domain $user = 'root'; // the username for this database $password = ''; // the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'gl_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) break; default; // default config if everything fails $db = 'wordpress'; // the database for this domain $user = 'root'; // the username for this database $password = '';// the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'wpmu_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) } /* * Handle multi domain into single instance of wordpress installation define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); */ define('DB_NAME', $db); define('DB_USER', $user); define('DB_PASSWORD', $password); define('DB_HOST', $hostname); define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); define ('WPLANG', $wplang); /**#@+ * Authentication Unique Keys. * * Change these to different unique phrases! * You can generate these using the {@link http://api.ww.wp.xz.cn/secret-key/1.1/ ww.wp.xz.cn secret-key service} * * @since 2.6.0 */ 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_ALLOW_REPAIR', true); define('WP_MEMORY_LIMIT', '512M'); define('WP_MAX_MEMORY_LIMIT', '512M'); define('MICROSOFT_TRANSLATE_CLIENT_ID', ''); define('MICROSOFT_TRANSLATE_CLIENT_SECRET', ''); define('GOOGLE_TRANSLATE_KEY', ''); define('FS_METHOD', 'direct'); define('WP_DEBUG', false); define('SCRIPT_DEBUG', false); /** @ini_set( 'log_errors', 'Off' ); @ini_set( 'display_errors', 'On' ); */ define('WP_DEBUG_LOG', false); define('WP_DEBUG_DISPLAY', false); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', true); define('DOMAIN_CURRENT_SITE', 'upi.loc'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); define( 'SUNRISE', 'on' ); /* That's all, stop editing! Happy blogging. */ define('WP_ALLOW_MULTISITE', true); /** WordPress absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); /** Sets up WordPress vars and included files. */ require_once(ABSPATH . 'wp-settings.php'); //--- disable auto upgrade /**define( 'AUTOMATIC_UPDATER_DISABLED', false );**/ ?>I’d put a print_r($host) and print_r($parts) at the top, followed by an exit(0) to see whether what you think you’re getting is what you’re actually getting.
You mean like this: ???
<?php
$host = $HTTP_HOST;
$parts = explode(‘.’,$host);
if ($parts[3] = ”) {
$domain = $parts[0];
} else {
$domain = $parts[1];
}print_r($host);
print_r($parts);exit(0)
?>egg-zactly
let’s see what’s in those variables.
Script:
<?php $host = $HTTP_HOST; $parts = explode('.',$host); if ($parts[3] = '') { $domain = $parts[0]; } else { $domain = $parts[1]; } print_r($host); print_r($parts); exit(0); ?>Result:
Notice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\vartest.php on line 2
Notice: Undefined offset: 1 in C:\xampp\htdocs\vartest.php on line 7
Array ( [0] => [3] => )well, it seems there’s a basic flaw!
try $_SERVER[‘HTTP_HOST’]
Ok, we are getting closer …
The site is starting and top left I see the $print_r():( [0] => german-lightning [1] => loc [3] => )
Script:
<?php $host = $_SERVER['HTTP_HOST']; $parts = explode('.',$host); if ($parts[3] = '') { $domain = $parts[0]; } else { $domain = $parts[1]; } print_r($host); print_r($parts); exit(0); ?>Domain: upi.loc
Result:
upi.locArray ( [0] => upi [1] => loc [3] => )
OK, you’re on the right track. Keep going. This isn’t a WordPress problem.
Delete the print_r’s.
Domain: german-lightning.loc
Result:
german-lightning.locArray ( [0] => german-lightning [1] => loc [3] => )removed them, but still the switch executes “default” only 🙁
it’s not a wordpress problem; it’s your coding. keep working on it.
True!
Now, it’s running …
Nice solution to run a single wordpress installation with multiple databases!!!/** Script to replace the standard defines for define('DB_NAME'); define('DB_USER'); define('DB_PASSWORD'); define('DB_HOST'); */ /** Determining the domain - DO NOT EDIT */ $host = $_SERVER['HTTP_HOST']; $domain = $host; /** Domain - Edit below. To add more domains: 1. Add a new "case" with copy/paste and edit the data for db, user, password, hostname. The name of the case shall be your domain name! 2. Create an empty database 3. Enter the domain in your browser and configure your database. */ switch ($domain) { case 'www.upi.loc'; // 'domain' in 'domain' NO WWW or TLD $db = 'upi'; // the database for this domain $user = 'root'; // the username for this database $password = ''; // the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'upi_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); break; case 'www.german-lightning.loc'; // 'domain' in 'domain' $db = 'gl'; // the database for this domain $user = 'root'; // the username for this database $password = ''; // the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'gl_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); break; default; // default config if everything fails $db = 'gl'; // the database for this domain $user = 'root'; // the username for this database $password = '';// the password for this database $hostname = 'localhost'; // 99% chance you won't need to change this value $table_prefix = 'gl_'; // change for multiple installations in one database define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); $wplang = 'de_DE'; // change to localize wordpress (must have an MO file in wp-includes/languages) define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); } define('DB_NAME', $db); define('DB_USER', $user); define('DB_PASSWORD', $password); define('DB_HOST', $hostname); define ('WPLANG', $wplang);
The topic ‘WP-CONFIG -PHP problem’ is closed to new replies.