Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-11-28 05:45:15

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

[howto] config.php for localhost & live site

To save time whilst moving sites between localhost and live I have been using the code below so I don’t have to edit the settings each time.

Its just a conditional which chooses local settings if the IP = the localhost one 127.0.0.1, and if not it chooses the live site settings.

This works on my server/localhost setup – but I was wondering if there any security issues I should be aware of?

<?php

$ip=$_SERVER['REMOTE_ADDR'];
if ($ip == '127.0.0.1') {

$txpcfg['db'] = 'local';
$txpcfg['user'] = 'local';
$txpcfg['pass'] = 'local';
$txpcfg['host'] = 'localhost';
$txpcfg['table_prefix'] = '';
$txpcfg['txpath'] = '/local/local/local';
$txpcfg['dbcharset'] = 'utf8';

} else {

$txpcfg['db'] = 'livesite';
$txpcfg['user'] = 'livesite';
$txpcfg['pass'] = 'livesite';
$txpcfg['host'] = 'localhost';
$txpcfg['table_prefix'] = '';
$txpcfg['txpath'] = '/livesite/livesite/livesite';
$txpcfg['dbcharset'] = 'utf8';

}	

?>

Offline

#2 2012-11-28 22:37:28

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: [howto] config.php for localhost & live site

Cool – I’ll keep using it then :)

Offline

#3 2013-11-19 18:14:04

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: [howto] config.php for localhost & live site

I do something not entirely dissimilar with my live/local setup (live: MediaTemple DV4, local: OS X localhost):

  • have common database names, users and passwords
  • always use 127.0.0.1 as the database host in config.php (my databases are always local)
  • symlink /var/www/vhosts/ (live server) to point to ~/Sites/ on my localhost

Last edited by gaekwad (2013-11-19 18:14:38)

Offline

Board footer

Powered by FluxBB