Friday, April 15, 2022

[SOLVED] PHP exec 'VBoxManage startvm'

Issue

I'm trying to start virtualbox machine throught PHP script on server. I wrote this script:

<?php
    echo(exec("sudo VBoxManage startvm 'EnterToJa'"));
?>

And it runs on server, but it waits only for first line:

Waiting for VM "EnterToJa" to power on...

After that it probably kills it. When I run that VBoxManage command on my server from terminal it works, but I have to wait ~5 seconds and I this that is the problem.

P.S.
www-data <- has got permission to run sudo without password


Solution

To make your VirtualBox work you have to add into your command line |at now.

Example:

<?php
    exec("sudo VBoxManage startvm 'EnterToJak' --type HeadLess|at now");
?>


Answered By - bilek993
Answer Checked By - Cary Denson (WPSolving Admin)