I used sudo command to accomplish this.
Create a new user, give him sudo full access without the need of password by editing the sudoers file in /etc/sudoeres so use username ALL=(ALL) NOPASSWD: ALL
Then make sure to use full path to the commands in php