• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

create a web based install script to install a database.

Good Morning Experts! Heres a easy one for you I hope. Worth 500.
I have a database that works with a website progam  but I want to install this on other servers.
I have dumped the database tables only to a text file via PHP MyAdmin. How do I create a php script that
will install this database on a new server?
It needs to be like a form.
server:
database:
dbuname:
dbpassword:
[SUBMIT]
Then it installs the database from the text file.
0
jbrashear72
Asked:
jbrashear72
  • 16
  • 12
  • 4
  • +1
1 Solution
 
fastball1945Commented:
do you want it to create a database?  or create tables in an existing database?  Eithor way i could get you the code.  I just need to find it on my computer.  :-/
0
 
jbrashear72Author Commented:
I have the database bumped into a text file. database.sql
0
 
fastball1945Commented:
Right.....but do you want to create the database or the tables inside an existing database?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jbrashear72Author Commented:
An existing database.
So Requirements.
USername password and database have to all be in place. We are just going to install the tables into this database.
0
 
fastball1945Commented:
You can try this....i have not tested it yet but i think it will work.

<?PHP
$db_host = "localhost";
$db_name = $_POST[name];
$db_user = $_POST[user];
$db_pass = $_POST[pass];


//connect to the database server
$db[connect] = mysql_connect($db_host, $db_user, $db_pass);

//report the connection failure or success
if (!$db[connect]) {
   echo "there was a problem connecting to the database.";
   exit;
}

if ($db[connect]) {
      $db[select] = $mysql_select_db($db_name);

      if (!$db[select]) {
            $filename = '/path/to/file';
            $handle = fopen($filename, "r");

            $contents = fread($handle, filesize($filename));

            fclose($contents);

      $mysql_query($db_name);
      }
      if ($db[select]) {
            echo "The database already exists!";
      }
}

?>
0
 
fastball1945Commented:
oops...the $mysql_query($db_name); line should be:

     $mysql_query($contents);
0
 
ldbkuttyCommented:
jbrashear72,

If this is just for your administration, you could use PHPMyAdmin. Or simply with the "source" command of MySql.  If you are really in need of a PHP Script, you can use exec( http://www.php.net/exec ) or passthru command. Like this:

<?php
    $filename = 'path/to/file.sql';
    $command = "mysql -u DB_USERNAME -p DB_PASSWORD DB_NAME < " . $filename;
    echo $command;
    if(exec($command)) {
          echo "Success";
    }
    else {
          echo "Error";      
    }
?>


// Replace the capital letter words with the original value.
// Make sure the file is set to chmod 0777 or 0755.

This is tested code, if this does not working make sure the sql is correct, you gave the right path to the file. Try as much as testing if problem exists. (The above code works fine in my Windows XP Box)

fastball1945,

From your posts in this question and other questions as well, its clear that you are certainly not a PHP Expert. Please refrain from posts that makes no sense. Thanks for your understanding.

btw, I'll not be available for the next 24 hours, I'll respond for any further questions later.
0
 
jbrashear72Author Commented:
What I am doing is I have to replicate a forum on many servers with the same site template.
I used PHP admin to dump a clean install of the database into a text file.
When I deploy the site to a new server. I do not want to rerun the install of the forum.
I want  to just have a quick install.php file as me for a username password and a database to install into.
Push submit and install the database on a new server. I know that I could do this with phpmyadmin but this is for people
that need it kept simple.
-J
0
 
ldbkuttyCommented:
Have you tried integrating my script with yours ? Try this:

<?php
if(isset($_POST["Submit"]) && !empty($_POST["Submit"])) {
    $filename = 'path/to/file.sql';
    $command = "mysql -u {$_POST['db_username']} -p {$_POST['db_password']} {$_POST['db_name']} < " . $filename;
    if(exec($command)) {
         echo "Success";
    }
    else {
         echo "Error";    
    }
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
DB Name: <input type="text" name="db_name" value="" /> <br />
DB Username: <input type="text" name="db_username" value="" /> <br />
DB Password: <input type="text" name="db_password" value="" /> <br />
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
}
?>
0
 
jbrashear72Author Commented:
That was great I tried it but it isn't working.
I recived the error.
Let me give you the sql that I am running:
http://www.teksavers.com/forum_sql2.sql
Thanks,
-J
0
 
iamanindianCommented:
How about this?

************************************************************
<?php
error_reporting( E_ALL );
function populate_db($dbname,$sqldump){
      mysql_select_db($dbname);
      $var_env_mqr = @get_magic_quotes_runtime();
      @set_magic_quotes_runtime(0);      
      $db_query = fread(fopen($sqldump, "r"), filesize($sqldump));      //We're assuming teh $sqldump to be in the same folder
      @set_magic_quotes_runtime($var_env_mqr);      
      if(!$result=mysql_query ($db_query)){
            echo mysql_error()."<br>";
      }
}

if(isset($_POST['Submit'])){
$db_address=trim($_POST['txt_dbaddress']);
$db_name=trim($_POST['txt_dbname']);
$db_userid=trim($_POST['txt_dbuserid']);
$db_passwd=trim($_POST['txt_dbpasswd']);
      //Start Installation
      @mysql_connect($db_address,$db_userid,$db_passwd) or die("Database selection failed with error: ".mysql_error());
      @mysql_select_db($db_name) or die("Database selection failed with error: ".mysql_error());
      echo "Successfully connected with database server & have also selected the database.<br>Database population in progress...<br>";
      //All looks ok, start db population
      populate_db($db_name,'forum_sql2_sql');      //If required, the SQL file can also be assigned dynamically
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Installation Process</title>
<style type="text/css">
<!--
.style5 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>

<body>
<table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#666666">
  <form name="finstaller" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"><tr>
    <td><table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td width="22%" valign="top"><span class="style5">Database Server Address:          </span></td>
        <td width="78%" valign="top"><input name="txt_dbaddress" type="text" id="txt_address"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Name:</span></td>
        <td valign="top"><input name="txt_dbname" type="text" id="txt_dbname"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database User Name: </span></td>
        <td valign="top"><input name="txt_dbuserid" type="text" id="txt_dbuserid"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Password: </span></td>
        <td valign="top"><input name="txt_dbpasswd" type="password" id="txt_dbpasswd"></td>
      </tr>
      <tr>
        <td valign="top">&nbsp;</td>
        <td valign="top"><input type="submit" name="Submit" value="Start Installation">
          &nbsp;&nbsp;
          <input type="reset" name="Reset" value="Reset"></td>
      </tr>
    </table></td>
  </tr></form>
</table>
</body>
</html>
<?php
}
?>
************************************************************

Well...you do have to put the routine validations in place...

Regards
WC
0
 
jbrashear72Author Commented:
WC I try to run but it fails after it get to the sec block of sql.
Works with this:
CREATE TABLE IF NOT EXISTS `phpbb_vote_desc` (
  `vote_id` mediumint(8) unsigned NOT NULL auto_increment,
  `topic_id` mediumint(8) unsigned NOT NULL default '0',
  `vote_text` text NOT NULL,
  `vote_start` int(11) NOT NULL default '0',
  `vote_length` int(11) NOT NULL default '0',
  PRIMARY KEY  (`vote_id`),
  KEY `topic_id` (`topic_id`)
) TYPE=MyISAM AUTO_INCREMENT=1


But anything more and it fails:

CREATE TABLE IF NOT EXISTS `phpbb_vote_desc` (
  `vote_id` mediumint(8) unsigned NOT NULL auto_increment,
  `topic_id` mediumint(8) unsigned NOT NULL default '0',
  `vote_text` text NOT NULL,
  `vote_start` int(11) NOT NULL default '0',
  `vote_length` int(11) NOT NULL default '0',
  PRIMARY KEY  (`vote_id`),
  KEY `topic_id` (`topic_id`)
) TYPE=MyISAM AUTO_INCREMENT=1







CREATE TABLE IF NOT EXISTS `phpbb_vote_results` (
  `vote_id` mediumint(8) unsigned NOT NULL default '0',
  `vote_option_id` tinyint(4) unsigned NOT NULL default '0',
  `vote_option_text` varchar(255) NOT NULL default '',
  `vote_result` int(11) NOT NULL default '0',
  KEY `vote_option_id` (`vote_option_id`),
  KEY `vote_id` (`vote_id`)
) TYPE=MyISAM


Please help
0
 
iamanindianCommented:
I see...ok...give me a few hours...I will get back during letr half of the day. No worries.

Regards
WC
0
 
jbrashear72Author Commented:
Thanks..
0
 
iamanindianCommented:
BTW...a quick note...
Does this script fail even when you try running the sql query without the comments like:
TYPE=MyISAM AUTO_INCREMENT=1

If it works...then fine...else, I will just clean up the code.

WC
0
 
jbrashear72Author Commented:
I didn't relize that they were comments. (=
By the way here is a link to the sql statement/dump:
http://www.teksavers.com/forum_sql2.sql
That is the file and yes it is in the same directory as this install script.
Thank you again.

-J
0
 
iamanindianCommented:
Those are not comments actually...(sorry..my mistake in clarifying). But as because they define the table type..wanted to ensure they are not causing the problem.
BTW...what is the MySQL version you are running?

WC
0
 
jbrashear72Author Commented:
OK. Not sure really.
Mysql version is 3.23.58

Also do you know anything about copying contents of a directory from one to another.

This works but I need to pass it the directorys and run it from a php script from the web.

copy_site.sh
(cd /home/sites/domain; tar -cf - *) | (cd /home/public_html/domain; tar -xf -)
0
 
iamanindianCommented:
Ok...let us try this...I have added some validation, but to be 100% accurate...more needs to be done. But, I hope this will serve the purpose.
Please try & let me know how it went.

**********************************************************************************************
<?php
error_reporting( E_ALL );
function populate_db($dbname,$sqldump){
      mysql_select_db($dbname);
      $var_env_mqr = @get_magic_quotes_runtime();
      @set_magic_quotes_runtime(0);      
      $db_query = fread(fopen($sqldump, "r"), filesize($sqldump));
      @set_magic_quotes_runtime($var_env_mqr);
      $sql = trim($db_query);
      $sql = ereg_replace("\n#[^\n]*\n", "\n", $sql);
      $sql_array=explode(";",$sql);
      $counter=0;
      foreach($sql_array as $key=>$val){
            $counter++;
            if($val!=""){
                  if(!$result=mysql_query ($val)){
                        echo "<font color=red>$counter: [ERROR]".mysql_error()."</font><br>";
                  }else{
                        echo "<b>$counter: [OK]</b><br>";
                  }
            }            
      }
}

if(isset($_POST['Submit'])){
$db_address=trim($_POST['txt_dbaddress']);
$db_name=trim($_POST['txt_dbname']);
$db_userid=trim($_POST['txt_dbuserid']);
$db_passwd=trim($_POST['txt_dbpasswd']);
      @mysql_connect($db_address,$db_userid,$db_passwd) or die("Database selection failed with error: ".mysql_error());
      @mysql_select_db($db_name) or die("Database selection failed with error: ".mysql_error());
      echo "Successfully connected with database server & have also selected the database.<br>Database population in progress...<br>";
      populate_db($db_name,'forum_sql2.sql');
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Installation Process</title>
<style type="text/css">
<!--
.style5 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>

<body>
<table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#666666">
  <form name="finstaller" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"><tr>
    <td><table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td width="22%" valign="top"><span class="style5">Database Server Address:          </span></td>
        <td width="78%" valign="top"><input name="txt_dbaddress" type="text" id="txt_address"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Name:</span></td>
        <td valign="top"><input name="txt_dbname" type="text" id="txt_dbname"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database User Name: </span></td>
        <td valign="top"><input name="txt_dbuserid" type="text" id="txt_dbuserid"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Password: </span></td>
        <td valign="top"><input name="txt_dbpasswd" type="password" id="txt_dbpasswd"></td>
      </tr>
      <tr>
        <td valign="top">&nbsp;</td>
        <td valign="top"><input type="submit" name="Submit" value="Start Installation">
          &nbsp;&nbsp;
          <input type="reset" name="Reset" value="Reset"></td>
      </tr>
    </table></td>
  </tr></form>
</table>
</body>
</html>
<?php
}
?>

**********************************************************************************************

Regards
WC
0
 
jbrashear72Author Commented:
Awsome...
Here was the output:
Its' long:
Successfully connected with database server & have also selected the database.
Database population in progress...
1: [OK]
2: [OK]
3: [OK]
4: [OK]
5: [OK]
6: [OK]
7: [OK]
8: [OK]
9: [OK]
10: [OK]
11: [OK]
12: [OK]
13: [OK]
14: [OK]
15: [OK]
16: [OK]
17: [OK]
18: [OK]
19: [OK]
20: [OK]
21: [OK]
22: [OK]
23: [OK]
24: [OK]
25: [OK]
26: [OK]
27: [OK]
28: [OK]
29: [OK]
30: [OK]
31: [OK]
32: [OK]
33: [OK]
34: [OK]
35: [OK]
36: [OK]
37: [OK]
38: [OK]
39: [OK]
40: [OK]
41: [OK]
42: [OK]
43: [OK]
44: [OK]
45: [OK]
46: [OK]
47: [OK]
48: [OK]
49: [OK]
50: [OK]
51: [OK]
52: [OK]
53: [OK]
54: [OK]
55: [OK]
56: [OK]
57: [OK]
58: [OK]
59: [OK]
60: [OK]
61: [OK]
62: [OK]
63: [OK]
64: [OK]
65: [OK]
66: [OK]
67: [OK]
68: [OK]
69: [OK]
70: [OK]
71: [OK]
72: [OK]
73: [OK]
74: [OK]
75: [OK]
76: [OK]
77: [OK]
78: [OK]
79: [OK]
80: [OK]
81: [OK]
82: [OK]
83: [OK]
84: [OK]
85: [OK]
86: [OK]
87: [OK]
88: [OK]
89: [OK]
90: [OK]
91: [OK]
92: [OK]
93: [OK]
94: [OK]
95: [OK]
96: [OK]
97: [OK]
98: [OK]
99: [OK]
100: [OK]
101: [OK]
102: [OK]
103: [OK]
104: [OK]
105: [OK]
106: [OK]
107: [OK]
108: [OK]
109: [OK]
110: [OK]
111: [OK]
112: [OK]
113: [OK]
114: [OK]
115: [OK]
116: [OK]
117: [OK]
118: [OK]
119: [OK]
120: [OK]
121: [OK]
122: [OK]
123: [OK]
124: [OK]
125: [OK]
126: [OK]
127: [OK]
128: [OK]
129: [OK]
130: [OK]
131: [OK]
132: [OK]
133: [OK]
134: [OK]
135: [OK]
136: [OK]
137: [OK]
138: [OK]
139: [OK]
140: [OK]
141: [OK]
142: [OK]
143: [OK]
144: [OK]
145: [OK]
146: [OK]
147: [OK]
148: [OK]
149: [OK]
150: [OK]
151: [OK]
152: [OK]
153: [OK]
154: [OK]
155: [OK]
156: [OK]
157: [OK]
158: [OK]
159: [OK]
160: [OK]
161: [OK]
162: [OK]
163: [OK]
164: [OK]
165: [OK]
166: [OK]
167: [OK]
168: [OK]
169: [OK]
170: [OK]
171: [OK]
172: [ERROR]You have an error in your SQL syntax near ''' at line 2
173: [ERROR]You have an error in your SQL syntax near ')', 'icon_wink.gif', 'Wink')' at line 1
174: [ERROR]You have an error in your SQL syntax near ''' at line 2
175: [ERROR]You have an error in your SQL syntax near '-)', 'icon_wink.gif', 'Wink')' at line 1
176: [OK]
177: [OK]
178: [OK]
179: [OK]
180: [OK]
181: [OK]
182: [OK]
183: [OK]
184: [OK]
185: [OK]
186: [OK]
187: [OK]
188: [OK]
189: [OK]
190: [OK]
191: [OK]
192: [OK]
193: [OK]
194: [OK]
195: [OK]
196: [OK]
197: [OK]
198: [OK]
199: [OK]
200: [OK]
201: [OK]
202: [OK]
203: [OK]
204: [OK]
205: [OK]
206: [OK]
207: [OK]
208: [OK]
209: [OK]
210: [OK]
211: [ERROR]You have an error in your SQL syntax near '--' at line 5
0
 
iamanindianCommented:
Ooops! Sorry about that.... :(

Actually...I checked your sql dump...& those lines are:

INSERT INTO `phpbb_smilies` VALUES (33, ';)', 'icon_wink.gif', 'Wink');
INSERT INTO `phpbb_smilies` VALUES (34, ';-)', 'icon_wink.gif', 'Wink');


I exploded the dump with ";" as separator...that is why you faced the error. Ok...checking.

WC

0
 
jbrashear72Author Commented:
NP.
I love your idea to explode the dump!
That is awsome.
were did you learn that?

Also is there a way to display that it is complete after all OK lines are done?
-J
0
 
iamanindianCommented:
Ok...I borrowed a strip function & this is how it stands now:

----------------------------------------------------------------------------------------------------------------
<?php
error_reporting( E_ALL );
function populate_db($dbname,$sqldump) {
      mysql_select_db($dbname);
      $var_env_mqr = @get_magic_quotes_runtime();
      @set_magic_quotes_runtime(0);
      $db_query = fread(fopen($sqldump, "r"), filesize($sqldump));
      @set_magic_quotes_runtime($var_env_mqr);
      $pieces  = split_sql($db_query);
      $errors = array();
      $counter=0;      
      for ($i=0; $i<count($pieces); $i++) {
            $counter++;
            $pieces[$i] = trim($pieces[$i]);
            if(!empty($pieces[$i]) && $pieces[$i] != "#") {
                  if (!$result = mysql_query ($pieces[$i])) {
                        $errors[] = array ( mysql_error(), $pieces[$i] );
                        echo "<font color=red>$counter: [ERROR]".mysql_error()."</font><br><hr>";                        
                  }else{
                        echo "<b>$counter: [OK]</b><br>";                  
                  }
            }
      }
}

function split_sql($sql) {
      $sql = trim($sql);
      $sql = ereg_replace("\n#[^\n]*\n", "\n", $sql);

      $buffer = array();
      $ret = array();
      $in_string = false;

      for($i=0; $i<strlen($sql)-1; $i++) {
            if($sql[$i] == ";" && !$in_string) {
                  $ret[] = substr($sql, 0, $i);
                  $sql = substr($sql, $i + 1);
                  $i = 0;
            }

            if($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") {
                  $in_string = false;
            }
            elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
                  $in_string = $sql[$i];
            }
            if(isset($buffer[1])) {
                  $buffer[0] = $buffer[1];
            }
            $buffer[1] = $sql[$i];
      }

      if(!empty($sql)) {
            $ret[] = $sql;
      }
      return($ret);
}


if(isset($_POST['Submit'])){
$db_address=trim($_POST['txt_dbaddress']);
$db_name=trim($_POST['txt_dbname']);
$db_userid=trim($_POST['txt_dbuserid']);
$db_passwd=trim($_POST['txt_dbpasswd']);
      //Start Installation
      @mysql_connect($db_address,$db_userid,$db_passwd) or die("Database selection failed with error: ".mysql_error());
      @mysql_select_db($db_name) or die("Database selection failed with error: ".mysql_error());
      echo "Successfully connected with database server & have also selected the database.<br>Database population in progress...<br>";
      populate_db($db_name,'forum_sql3.sql');
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Installation Process</title>
<style type="text/css">
<!--
.style5 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>

<body>
<table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#666666">
  <form name="finstaller" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"><tr>
    <td><table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td width="22%" valign="top"><span class="style5">Database Server Address:          </span></td>
        <td width="78%" valign="top"><input name="txt_dbaddress" type="text" id="txt_address"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Name:</span></td>
        <td valign="top"><input name="txt_dbname" type="text" id="txt_dbname"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database User Name: </span></td>
        <td valign="top"><input name="txt_dbuserid" type="text" id="txt_dbuserid"></td>
      </tr>
      <tr>
        <td valign="top"><span class="style5">Database Password: </span></td>
        <td valign="top"><input name="txt_dbpasswd" type="password" id="txt_dbpasswd"></td>
      </tr>
      <tr>
        <td valign="top">&nbsp;</td>
        <td valign="top"><input type="submit" name="Submit" value="Start Installation">
          &nbsp;&nbsp;
          <input type="reset" name="Reset" value="Reset"></td>
      </tr>
    </table></td>
  </tr></form>
</table>
</body>
</html>
<?php
}
?>
----------------------------------------------------------------------------------------------------------------
Regards
WC
0
 
iamanindianCommented:
Ooops! Miskate again...it was a split function (& not strip ;) )

And...sure, if you want to show a confirmation:

Either after calling the populate_db or within that...you print a confirmation e.g.

echo "<hr><b>DB update over!</b><hr>";


Regards
WC
0
 
iamanindianCommented:
Oh...regarding your query...
explode is a handy function from PHP...it should have worked, but I missed the possiblity of ";" within the query. That is why a splitter was needed...though it adds more coding...but is safer...it basically breaks the dump is individual strings...& then executes the queries.

WC
0
 
jbrashear72Author Commented:
That is awsome. Thanks again....
Also do you know anything about copying contents of a directory from one to another.

This works but I need to pass it the directorys and run it from a php script from the web.
Here is the shell script that I have.

copy_site.sh
(cd /home/sites/domain; tar -cf - *) | (cd /home/public_html/domain; tar -xf -)
0
 
jbrashear72Author Commented:
Also do you know how I can aword you more points?
-J
0
 
iamanindianCommented:
:) I am not well aware of the pointing system...I am happy as long as I could be of some help (I don't mind points though).

Regarding file/folder copying...if you have a running shell script, why not use shell_exec to execute that shell script?
It could be like:

<?php
$output = shell_exec('yourscript.sh');
echo "<pre>$output</pre>";
?>

Hope this make sense.
Regards
WC
0
 
jbrashear72Author Commented:
Yep, Funny I just did it with this:
<?php

shell_exec("/home/copy_site.sh /home/v6-nadg/public_html/sites/mortgageloan-news.com/ /home/test/");

?>

Is it better to do it like this:
<?php
$output = shell_exec('/home/copy_site.sh /home/v6-nadg/public_html/sites/mortgageloan-news.com/ /home/test/');
echo "<pre>$output</pre>";
?>
0
 
jbrashear72Author Commented:
Here is what I am doing:

This is what I want but it doesnt work:
<html>
<head>
<title>Site going Live</title>
<body>
Loading site Please waite...
<?php
$source = "/home/nadg/public_html/sites/domain.com/";
$dest = "/home/domain/public_html/";
$output = shell_exec('/home/copy_site.sh $source $dest');
echo "<pre>$output</pre>";
?>
</body>
<html>

This does work but I need the source and dest to be dynamic:
<html>
<head>
<title>Site going Live</title>
<body>
Loading site Please waite...
<?php
$output = shell_exec('/home/copy_site.sh /home/nadg/public_html/sites/domain.com/ /home/domain/public_html/');
echo "<pre>$output</pre>";
?>
</body>
<html>
0
 
iamanindianCommented:
Hmnn...
Unfortunately...at this moment I don't hace access to a Linux box...so can't tell you for sure, but how about trying something like this:

$output = shell_exec($command);
echo "<pre>$output</pre>";


Now, in the $command you write the complete shell script code including the dynamically assigned source & destination. Thus, before reaching the shell_exec line, your $command variable will be storing something like "'/home/copy_site.sh /home/nadg/public_html/sites/domain.com/ /home/domain/public_html/'
So test this with an echo to be sure that $command is storing the correct information...before actually calling shell_exec.

Let us see how it goes.
Regartds
WC
0
 
jbrashear72Author Commented:
OK that didn't work so I am doing something crazy but it works.
But I think that this is way to much work.
-J
<?php
$source = "domain.com";
$dest = str_replace(".com","",$source);


// Loads the site copy template into memory
$copysite = file_get_contents("run.tpl");

// Locates tokens in the template and replaces with template vars
$working_template  = "$copysite";
      $patterns = array("%DOMAINNAME%", "%DOMAINDIR%");
$replacements = array("$source", "$dest");

$newtemplate = str_replace($patterns, $replacements, $working_template);
$keyword = "run";
$filename = ("run/".$keyword.".php");

//Open new file thes create the main template for each keyword
$myfile = fopen($filename, "w+");
fwrite($myfile, $newtemplate);
$msg = "<p>Copy Script created</P>";
fclose($myfile);




?>

<html>
<head>
<title>Step 1 creating copy script.</title>
</head>
<body>
Loading site Please waite...
<? echo "$msg"; ?>
<a href= "/run/run.php">OK Make it live</a>
<body>
<html>
0
 
iamanindianCommented:
:) Ok...sounds good. As long it works...everyone should be happy.
I will try & see if I could execute your shell on a linux box & will get back. But...please don't wait for me...as I am going out on a vacation (boy...I am happy :))...so will be off-track for the next 2 weeks.

All the best!

Regards
WC
0
 
jbrashear72Author Commented:
Well you have a great time. And try not to touch a computer. (=
-J
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 16
  • 12
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now