'PHP Shell EXEC with Plesk
- I made a SH script to add Plesk subscription (newplesk.sh)
- I need this script to be started from a PHP file.
- It's working through SSH when typing
php testplesk.php
- It's not working when I enter the direct path into web browser (https://example.com/testplesk.php)
testplesk.php :
<?php
/// testplesk.php
exec('php testshell.php');
?>
testshell.php :
<?php
/// testshell.php
shell_exec('sudo sh newplesk.sh');
?>
newplesk.sh :
plesk bin subscription --create 6.domain.tld -owner admin -service-plan "Default Domain" -ip xxx.xxx.xxx.xxx -login jdoe6 -passwd "pwd6"
All of these files are chown in xxx:psacln
Any help please ? Best Regards.
EDIT (Reason : Answer)
The web user had to be in sudoers and the path to plesk in absolute path
nano /etc/sudoers
Last line of "sudoers" :
yourwebuser ALL = NOPASSWD: /usr/sbin/plesk
newplesk.sh (modified & with var) :
sudo /usr/sbin/plesk bin customer --create $1 -name $2 -passwd sample -phone $4 -company $5 -email $6 -notify false
Thanks to Luka who helped me for that
Solution 1:[1]
Actually your method is unsecure. I think you can do your process with Plesk API.
For example:
curl -i -X GET -u admin:***** "https://yourserver-address:8443/api/v2/server"
You can run this command with PHP curl or guzzle.
This method is safer and more convenient than the previous one.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Cryptograph |