Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[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
Re: [howto] config.php for localhost & live site
Cool – I’ll keep using it then :)
Offline
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