简体   繁体   中英

Run Scripts from PHP

I have a question about interaction PHP and Linux system.

I want to launch Steam from WebPage, and address of this page is

http://site.eu/cp/user/services/21/steaminstall

And internal path to WebPage from where im running command is

/var/www/wwwuser/data/www/site.eu/panel.php?(here goes $_POST[''] data)

and the Steam Client is

/var/www/wwwuser/data/Steam/SteamInstall

The thing is, i know how to access this script, also i can execute simple

echo "Script is Runing"

But when my actions comes to this code

#!/bin/bash
wget -P /var/www/aftersoft/data/Servers/Steam/ http://media.steampowered.com/client/steamcmd_linux.tar.gz &&
tar xvfz /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz -C /var/www/aftersoft/data/Servers/Steam/ &&
sh /var/www/aftersoft/data/Servers/Steam/steamcmd.sh +login anonymous +quit &&
rm /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz &&
echo "Steam Installation and Update Completed"

It's not doing anything if im running it from WebPage, but it works when im trying to run it under the SSH user (same as apache user with permissions to write to this folder)

So my question, what am i doing wrong?

UPDATE: My php code to run script is

if($path[2] === 'steaminstall')
{
    $InstallSteam = exec('/var/www/aftersoft/data/Servers/Steam/SteamInstall', $Output, $Error);
    if($Error === 0)
    {
      $Status = $DB->SteamStatus($_SESSION['username']);
      if($Status)
      {
         header('Location: /cp/'.$_SESSION['username'].'/services/');
      }
      else
      {
         $Smarty->assign('InstallStatus', 'Database Error Occured');
         $Smarty->display('steaminstall.tpl');
      }
    }
    if($Error === 2)
    {
       $Smarty->assign('InstallStatus', $Output);
       $Smarty->display('steaminstall.tpl');
    }
}

And this is my database query function

public function SteamStatus($Username)
{
    $Status = '1';
    $Statement = $this->DBConnection->prepare("UPDATE account set steaminstalled = ? where username = ?");
    $Statement->bindParam(1, $Status);
    $Statement->bindParam(2, $Username);
    $IStatus = $Statement->execute();
    if($IStatus)
    {
       return true;
    }
    else
    {
       return false;
    }
}

Problem solved, you just need to specify direct path to your script (as if you dont, the script itself dont know where to download and where to extract)

So the final bash script (PHP part is perfectly fine):

#!/bin/bash
wget -P /var/www/aftersoft/data/Servers/Steam/ http://media.steampowered.com/client/steamcmd_linux.tar.gz &&
tar xvfz /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz -C /var/www/aftersoft/data/Servers/Steam/ &&
sh /var/www/aftersoft/data/Servers/Steam/steamcmd.sh +login anonymous +quit &&
rm /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz &&
echo "Steam Installation and Update Completed"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM