Search code examples
phpplesk

How to execute shell commands from plesk extension


i'm making an extension that use a php file in the 'public' directory as a webhook.

From this hook, I will need to run some shell commands (things like npm run build or similar). Is there some kind of api from plesk that let me do this? Or should I use a php function like exec or shell_exec?


Solution

  • I looked through the net, but in the end it looks like what I'm trying to accomplish is not doable. You can indeed use shell_exec to run shell commands, but the user used to run this commands is psaadm, which is a severely restricted user when operating inside a domain document folder. You can see the files, but not create or execute any script, which renders this function useless for what I wanted to do.

    If you want to use a webhook tu run your npm build (or other scripts), you can always create a php file in the document root folder and execute your commands using shell_exec. When you call this file, it will execute the commands as the customer user, and will have the ability to run those scripts.

    P.S. It might actually be accomplished if you change the permission for the psaadm user, but it's not something a customer which install an extension should do. Still, not sure if it will work for the domain document root folder of your customers.