Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-08-15 22:11:47

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

2 different setting for the config.php

Hi, I want to have two different settings in my config file.

One for local machine and one for live site.

Is there any way I can create the local machine config a priority.

When a site is live, it should read the config, if the “local” config fails and it goes to the “live” config. I believe it could be achieved with php conditionals?

Thanx


<txp:way_too_cool />

Offline

#2 2011-08-15 22:21:38

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: 2 different setting for the config.php

Please stop me if this is an irregular method

<?php

if ($_SERVER['HTTP_HOST'] == "site.personal.dev") {
    $active_group = 'dev';
} elseif ($_SERVER['HTTP_HOST'] == "www.site.com") {
	$active_group = 'production';
}


$txpcfg['default']['db'] = 'site';
$txpcfg['default']['user'] = 'root';
$txpcfg['default']['pass'] = 'root';
$txpcfg['default']['host'] = 'localhost';
$txpcfg['default']['table_prefix'] = '';
$txpcfg['default']['txpath'] = '/Users/Dimitri/Sites/site.dev/textpattern';
$txpcfg['default']['dbcharset'] = 'utf8';


$dbtxpcfg'dev'] = $txpcfg['default'];
$txpcfg['dev']['db'] = 'site';
$txpcfg['dev']['user'] = 'root';
$txpcfg['dev']['pass'] = 'root';
$txpcfg['dev']['host'] = 'localhost';
$txpcfg['dev']['txpath'] = '/Users/Dimitri/Sites/site.dev/textpattern';


$txpcfg['production'] = $txpcfg['default'];
$txpcfg['production']['db'] = 'sitesql';
$txpcfg['production']['user'] = 'username';
$txpcfg['production']['pass'] = 'password';
$txpcfg['production']['host'] = '169.0.0.1'; //random ip address
$txpcfg['production']['txpath'] = '/public_html/textpattern';


?>

Last edited by Dimitri (2011-08-15 22:44:07)


<txp:way_too_cool />

Offline

#3 2011-08-15 22:33:13

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: 2 different setting for the config.php

It doesnt work :/

Can anyone help me?


<txp:way_too_cool />

Offline

#4 2011-08-15 22:46:13

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: 2 different setting for the config.php

I’d assume you could do something like this: (used config-dist.php)

<?php

if ($_SERVER['HTTP_HOST'] == "site.personal.dev") {

/**
	 *  mysql database
	 */
		$txpcfg['db'] = 'databasename';

	/**
	 *  database login name
	 */
		$txpcfg['user'] = 'root';

	/**
	 *  database password
	 */
		$txpcfg['pass'] = '';

	/**
	 *  database host
	 */

		$txpcfg['host'] = 'localhost';

	/**
	 *  table prefix (Use ONLY if you require multiple installs in one db)
	 */

		$txpcfg['table_prefix'] = '';

	/**
	 *  full server path to textpattern dir (no slash at end)
	 */

		$txpcfg['txpath'] = '/home/path/to/textpattern';

	/**
	 *  DB Connection Charset, only for MySQL4.1 and up. Must be equal to the Table-Charset.
	 */

		$txpcfg['dbcharset'] = 'latin1';

	/**
	 *  optional: database client flags as needed (@see http://www.php.net/manual/function.mysql-connect.php)
	 */

	#	$txpcfg['client_flags'] = MYSQL_CLIENT_SSL | MYSQL_CLIENT_COMPRESS;

	/**
	 *  optional, advanced: http address of the site serving images
	 *  @see http://forum.textpattern.com/viewtopic.php?id=34493
	 */

	# define('ihu', 'http://static.example.com/');


} elseif ($_SERVER['HTTP_HOST'] == "www.site.com") {

/**
	 *  mysql database
	 */
		$txpcfg['db'] = 'databasename';

	/**
	 *  database login name
	 */
		$txpcfg['user'] = 'root';

	/**
	 *  database password
	 */
		$txpcfg['pass'] = '';

	/**
	 *  database host
	 */

		$txpcfg['host'] = 'localhost';

	/**
	 *  table prefix (Use ONLY if you require multiple installs in one db)
	 */

		$txpcfg['table_prefix'] = '';

	/**
	 *  full server path to textpattern dir (no slash at end)
	 */

		$txpcfg['txpath'] = '/home/path/to/textpattern';

	/**
	 *  DB Connection Charset, only for MySQL4.1 and up. Must be equal to the Table-Charset.
	 */

		$txpcfg['dbcharset'] = 'latin1';

	/**
	 *  optional: database client flags as needed (@see http://www.php.net/manual/function.mysql-connect.php)
	 */

	#	$txpcfg['client_flags'] = MYSQL_CLIENT_SSL | MYSQL_CLIENT_COMPRESS;

	/**
	 *  optional, advanced: http address of the site serving images
	 *  @see http://forum.textpattern.com/viewtopic.php?id=34493
	 */

	# define('ihu', 'http://static.example.com/');


}

?>

edit: fixed the elseif. How I missed that I do not know.

Last edited by MattD (2011-08-16 15:32:56)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2011-08-15 22:57:44

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: 2 different setting for the config.php

Hey thanx.

I had a php error.

} else was suppose to be } elseif

It works fine on my local machine but it is corrupt on production site :/

<?php

if ($_SERVER['HTTP_HOST'] == "site.personal.dev") {

		$txpcfg['db'] = 'site';
		$txpcfg['user'] = 'root';
		$txpcfg['pass'] = 'root';
		$txpcfg['host'] = 'localhost';
		$txpcfg['table_prefix'] = '';
		$txpcfg['txpath'] = '/Users/Dimitri/Sites/site.dev/textpattern';
		$txpcfg['dbcharset'] = 'utf8';

} elseif ($_SERVER['HTTP_HOST'] == "www.site.com") {

	$txpcfg['db'] = 'site';
	$txpcfg['user'] = 'name';
	$txpcfg['pass'] = 'pass';
	$txpcfg['host'] = '169.0.0.1';
	$txpcfg['table_prefix'] = '';
	$txpcfg['txpath'] = '/site/html/textpattern';
	$txpcfg['dbcharset'] = 'utf8';
}

?>

<txp:way_too_cool />

Offline

#6 2011-08-15 23:23:39

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: 2 different setting for the config.php

If you are not exactly sure to which hostnames the production server answers, or to what the final domain is, but you know your localhost address, then you could easily do:

<?php

/*
	Applies to both (these couldn't be different anyway)
*/

$txpcfg['table_prefix'] = '';
$txpcfg['dbcharset'] = 'utf8';

/*
	Configuration for the production environment
*/

$txpcfg['db'] = 'site';
$txpcfg['user'] = 'name';
$txpcfg['pass'] = 'pass';
$txpcfg['host'] = '169.0.0.1';
$txpcfg['txpath'] = '/site/html/textpattern';

if($_SERVER['HTTP_HOST'] == 'site.personal.dev') {

	/*
		Configuration for local environment
	*/ 

	$txpcfg['db'] = 'site';
	$txpcfg['user'] = 'root';
	$txpcfg['pass'] = 'root';
	$txpcfg['host'] = 'localhost';
	$txpcfg['txpath'] = '/Users/Dimitri/Sites/site.dev/textpattern';
}

?>

Offline

#7 2011-08-16 16:40:09

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: 2 different setting for the config.php

Excellent. Thanx


<txp:way_too_cool />

Offline

Board footer

Powered by FluxBB