Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PHP-DB] Prod and Dev environments/management

0 views
Skip to first unread message

Jason Stechschulte

unread,
Oct 9, 2001, 4:28:07 PM10/9/01
to DL Neil, php...@lists.php.net
On Tue, Oct 09, 2001 at 07:34:22PM +0100, DL Neil wrote:
> Do you keep separate MySQL (et al) databases, eg dbOrders_Tst,
> dbOrders_Prd, or simply have differently named tables within one db,
> eg tblOrders_Tst, tblOrders_Prd? Once separated, when coding your
> PHP, how do you 'point' the script to the appropriate db/tables?

The best way is to have a dev server and a production server. I don't
have that luxary either, so here is what I do. I keep separate
databases and keep separate include directories. I also have two
scripts that help with all of this. The first one is the one I use to
backup my Mysql databases, and I also use it to restore them to test
databases. I simply prepend test_ to all of my databases. That script
is called mysql_backup.pl and is below. The second script is one I use
to move files from my test environment to production environment.

I set up a cron job to run mysql_backup.pl every night. golive.pl is a
script I use to move a file to production as I finish testing it. I
call it like this:

golive index.php (This is for one file)

or

golive * (This is for an entire directory)


mysql_backup.pl:

#!/usr/bin/perl

$now = time;
$directory = "/home/backups";
@databases = ("mysql", "database1", "database2");

foreach $database (@databases) {
$backup = "mysqldump \-\-add-drop-table -u user -ppassword
$database";
$zip = "| gzip > $directory/$database.$now.gz";
system("$backup $zip");

# This stays commented, because I don't want to restore all the time.
# unless($database eq "mysql") {
# $restore = "|mysql -u user -ppassword test_$database";
# system("$backup $restore");
# }
}

golive.pl:

#!/usr/bin/perl

# Figure out where we are running this from
chomp ($path = `pwd`);

# Create a new path to where we are going to copy to
$newpath = $path;
$newpath =~ s/test_site/www/;
$newpath =~ s/test_phpdocs/phpdocs/;

# Set lastFile equal to empty string to initialize it
$lastFile = '';

# Loop through all of the input one line at a time
while(<>){
unless($ARGV eq 'univ_master.php') {
if($lastFile ne $ARGV) {
if($lastFile ne "") {
close TMP;
`cp $oldfile $newfile`;
`chgrp www-data $newfile`;
`chmod 660 $newfile`;
unlink ($oldfile);
print "$lastFile now live\n";

}
$lastFile = $ARGV;
open TMP, ">$path/$ARGV.tmp";

$oldfile = "$path/$ARGV.tmp";
$newfile = "$newpath/$ARGV";
}

s/test_site/www/g;
s/test_phpdocs/phpdocs/g;
s/test_nwdata/nwdata/g;
s/test_user_accounts/user_accounts/g;

print TMP;
}
}
unless($ARGV eq 'univ_master.php') {

close TMP;

$oldfile = "$path/$lastFile.tmp";
$newfile = "$newpath/$lastFile";

`cp $oldfile $newfile`;
`chgrp www-data $newfile`;
`chmod 660 $newfile`;
unlink ($oldfile);
print "$lastFile now live\n";
}


>
> Alternatively, how do you ensure that testing/playing/dev work doesn't
> foul production data?
>
> Enquiring minds... =dn
>
> PS my personal dev env is NTWusS 4.0, PHP4, MySQL, and Apache

--
Jason Stechschulte
jps...@unoh.edu
--
If you want to see useful Perl examples, we can certainly arrange to have
comp.lang.misc flooded with them, but I don't think that would help the
advance of civilization. :-)
-- Larry Wall in <1992Mar5.1...@netlabs.com>

0 new messages