• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Root SSH with PHP?

safemoon

Basic Pleskian
Hello,

How can access specific folders of the server and add new files to that path?

What im trying to achieve is the following

- Create customer account via Plesk REST API (DONE)
- Create domain via Plesk REST API (DONE)

- Create DB via Plesk REST API (DONE)
- Go to that domain folder and run a php script that will install a software, to be more precise extract a zipped file (NOT DONE)
 
Last edited:
Update: Let' take the following example.

I have a file.php in /var/www/vhosts/domain1.com/httpdocs/file,php when I visit domain1.com/file.php I would like to download / auto-install (unzip) a zip file that contains the PHP app files to another domain (domain2.com - /var/www/vhosts/domain2.com/httpdocs/).

Basically, I want to create an auto-installer script that will install my PHP software to other domains on the same server. (I have already created the customer account in Plesk, domain, and DB via the REST API).

Thank you for your help and great community!
 
I have a file.php in /var/www/vhosts/domain1.com/httpdocs/file,php when I visit domain1.com/file.php I would like to download / auto-install (unzip) a zip file that contains the PHP app files to another domain (domain2.com - /var/www/vhosts/domain2.com/httpdocs/).
Be careful, you are setting yourself up for vulnerability if you run or execute scripts as a root user (no matter whether you run PHP files as root directly or run SSH commands as a root user). It's not safe.

The route I would go is to take advantage of the Eventmanager in Plesk. You can setup a Event Handler that fires when a new domain/subscription is added (Default domain event) and runs a script. Could be a simple Bash script or a PHP script. You let that script handle the downloading and unzipping.

All in all it's a bit more complex and more work to setup, but much safer. It has the additional benefit of off loading the downloading and extracting the zip file(s), which reduces the execution time of your PHP script.
 
Last edited:
Thank you I installed it according to your instructions, i can see the ssh2 extension in the phpinfo page. But im getting the following error, i restarted apache as well.
Code:
Call to undefined function  ssh2_connect()

PS: Not sure if it matters but under PHP extensions in Plesk i dont see the ssh2 checkbox
Be careful, you might be setting yourself up for vulnerability if you run or execute scripts as a root user (no matter whether you run PHP files as root directly or run SSH commands as a root user). It's not very safe.

The route I would go is to take advantage of the Eventmanager in Plesk. You can setup a Event Handler that fires when a new domain/subscription is added (Default domain event) and runs a script. Could be a simple Bash script or a PHP script. You let that script handle the downloading and unzipping.

All in all it's a bit more complex and more work to setup, but much safer. It has the additional benefit of off loading the downloading and extracting the zip file(s), which reduces the execution time of your PHP script.
Thank you, useful information! But im not sure if this will fulfill my requirements because many domains will be created on that site manually as well..
 
Update: I can see the "ssh2" checkbox under Plesk settings and its enabled but i still do get the error
"Fatal error: Uncaught Error: Call to undefined function ssh2_connect()"

PHP 7.4 FASTCGI
 
This is a poor idea as @Rasp said.

In order to execute the action you want, you'd need the user running PHP to be root (or give them access via Sudo) - which is really quite a poor security practice.

I'd recommend utilizing a Plesk extension and calling sbinCall("bin", ["args"]) to execute a privileged action from Plesk and accomplish what you want.
 
This is a poor idea as @Rasp said.

In order to execute the action you want, you'd need the user running PHP to be root (or give them access via Sudo) - which is really quite a poor security practice.

I'd recommend utilizing a Plesk extension and calling sbinCall("bin", ["args"]) to execute a privileged action from Plesk and accomplish what you want.
SSH2 managed to work, the user that is running the PHP Script is not root but is the webadmin of that domain (domain1.com) - is it still a security issue?

Secondly, where can I get more details on how to use that Plesk extension? Is it possible to call a specific event for a specific domain?
How would my script be able to install the php app on that newly created domain and avoid it from running when a new domain is created manually through the plesk area.
 
Back
Top