I'm making a php panel from which you can install apps like owncloud & plex on your server. I've created multiple bash scripts that install and remove software. I tested all of them from shell, everything works as it should. However, when I run the scripts from php as root using sudo on ubuntu 15.10, apt-get & dpkg are not working as they should.
In visudo I have:
seedbox ALL = (root) NOPASSWD: /bin/appinstaller
appinstaller is a bash script that run the install/uninstall apps bash scripts (e.g. appinstaller plex)
Plex script example:
dpkg --configure -a cd /tmp wget https://downloads.plex.tv/plex-media-server/0.9.15.6.1714-7be11e1/plexmediaserver_0.9.15.6.1714-7be11e1_amd64.deb dpkg -i plexmediaserver_0.9.15.6.1714-7be11e1_amd64.deb
When I run appinstaller directly from bash everything works perfectly.
When I run appinstaller from php using (confirmed that script is running as root):
exec("sudo /bin/appinstaller plex > /home/installer.log 2>&1 &");
It works but I get apt & dpkg errors when I try to install other apps such as:
E: The package plexmediaserver needs to be reinstalled, but I can't find an archive for it. (even though it's installed and working)
dpkg --configure -a returns an error.
Plex is working fine, but seems like apt doesn't finish the installation process and gets stuck somewhere, also commands running after the
dpkg won't run from php but will run from bash. I tried to run the script also from cron & systemctl and I get the same issue.
It's worth noting that some apps are installing/uninstalling without any issues.
What could be making the difference between running the script from php/cron/systemctl or from shell directly? Can I emulate normal bash session?