title: executing centos commands from php script
body: <p>I am working on a centos server and i have to download data from different server to the centos server in tbz format, then i have to extract it and after completion of the extraction i have to import data from it to mysql database table.</p>
  
  <p>what i am doing is 
  Getting data from the server which is around 700MB in size but when i am executing command to extract it and others nothing happens.</p>
  
  <pre><code>$files =   array('20111101.tbz', '20111101.tbz.md5' ,'20111102.tbz' ,'20111102.tbz.md5') ;
  
      //folder names of the folders formed
      $folder1 = "20111101";
      $folder3 = "20111102";
  
      //command to extract all the downloaded .tbz files
      $command1 = "cd /var/www/html/mywork1/mywork2/mywork3/";
      exec($command1." 2&gt;&amp;1", $output);
      $command2 = "tar -xjf ".$files[0];
      exec($command2." 2&gt;&amp;1", $output);
      $command4 = "tar -xjf ".$files[2];
      exec($command4." 2&gt;&amp;1", $output);
  
      //command to populate the data into the database
      $command6 = "cd /var/www/html/mywork1/mywork2/mywork3/mywork4";
      exec($command6." 2&gt;&amp;1", $output);
      $command7 = "./runit.py /var/www/html/mywork1/mywork2/mywork3/$folder1";
      exec($command7." 2&gt;&amp;1", $output);
      $command9 = "./runit.py /var/www/html/mywork1/mywork2/mywork3/$folder3";
      exec($command9." 2&gt;&amp;1", $output);
  
      //command to remove the folders created after population of data
      $command10 = "rm -rf $folder1";
      exec($command10." 2&gt;&amp;1", $output);
      $command11 = "rm -rf $folder3";
      exec($command11." 2&gt;&amp;1", $output);
  
      foreach ($files as $file) 
      {
          //command to remove all .tbz files downloaded.
          $command12 = "rm -rf $file";
          exec($command12." 2&gt;&amp;1", $output);
      }
  </code></pre>
  
  <p>i am simply executing the commands but its not doing anything. But when i try all these commands manually on server they work fine. Can any one guide me on this? What should be the correct approach to do this?</p>