Currently I am working on a project which require to create a vm from a click on the webpage.
This is my bash script which i am using to create a vm and it is working perfect but when called through php i am unable to run this script.
#!/bin/bash
set -e
if [ ! -f "/tmp/value.dat" ] ; then
value=0
else
value=`cat /tmp/value.dat`
fi
value=`expr ${value} + 1`
echo "${value}" > /tmp/value.dat
qemu-img create -f raw /var/lib/libvirt/images/disk$value.img 5.1G
virt-install --name=instance$value --ram=1024 --arch=i686 --vcpus=1 --os-type=linux --disk path=/var/lib/libvirt/images/disk$value.img,bus=virtio,format=raw --location ftp://10.21.40.227/ --extra-args "ks=ftp://10.21.40.227/ks.cfg" --autostart
This is the php script that i am trying to run
<?php
$bashfile = shell_exec("sudo /root/Desktop/install.sh");
echo "<pre>$bashfile<pre>";
?>
This is the entry in the sudoers file by me
apache ALL=(ALL) NOPASSWD: ALL
Still i am unable to run the bash script via php suggest some solutions.