Rex NEBULAR
Rex NEBULAR

Reputation: 13

PHP Shell EXEC with Plesk

  1. I made a SH script to add Plesk subscription (newplesk.sh)
  2. I need this script to be started from a PHP file.
  3. It's working through SSH when typing php testplesk.php
  4. 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

Upvotes: 0

Views: 1155

Answers (1)

Cryptograph
Cryptograph

Reputation: 46

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.

Upvotes: 1

Related Questions