简体   繁体   中英

PHP exec operator doesn't execute specific command

One of my lines of shell command is not executing despite other similar lines working. I am running on a linux machine using a Ubuntu 12.04 based OS. I have tried using exec as well, still doesn't work.

I actually had this working at some point, where I ran into the hanging issue (waiting for command output), which is why I'm redirecting output to /dev/null. So some where in the development something changed. We did create a debian package to install with and I had run that install package so I thought maybe in overwriting a file the permissions got changed so I added read/write/execute to all users/groups/owners but that didn't work either.

The code is here:

if(isset($_POST['activateXML']))
{
    if (videoConsistencyCheck())
    {
        `cp {$fileXML} /apps/video/xml.xml`;
        `sudo /apps/video/vsss restart >/dev/null 2>&1 &`;
        systemUnvalidate();
        header('Location: index.php?app='.$_GET['app']);
        die();
    }
}

I know that the first line in the if statement gets executed. The line of code works fine in the actually terminal, so that isn't the problem either. I did lots of Googling and all I could find is an unanswered question, any advice would be helpful.

EDIT: so what appeared to be not working was in fact calling the command as intended but in the bash script I was calling the start-stop daemon was not working

EDIT 2: I made a test php file and ran the code from the terminal, fixed the start-stop-daemon error by adding sudo to the commands but it still doesn't work in my code. I am calling this code when a submit button is pressed.

use additional parameters, especially output: exec($command,$output); var_dump($output); to determine what can be wrong with your command. If it doesn't work, please show us your code where you use your exec's.

The issue lay with a call to a binary file in the vsss script that could only be run as root. We did not want to allow access to that binary file to just anyone. The solution we came up with involves calling chmod +s on the vsss script which allows permissions for user and group IDs but keeps its owner permissions. We then added the PHP user, which was www-data, to the sudoers file using the NOPASSWD parameter. In my PHP code I then used the line:

exec('sudo /apps/video/vsss restart >/dev/null 2>&1 &')

The shell_exec() /backticks would not work with this method.

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