Script execution and PHP/Node version management on Plesk servers

This documentation covers best practices for running CLI (command line) scripts on a Plesk server in a multi-user environment, as well as managing the different versions of PHP and Node available.
The aim is to guarantee :

  • correct script execution without permissions problems,
  • consistent use of user environments,
  • and optimal security by avoiding bad practices (such as giving sudo rights to simple users).

It is primarily aimed at administrators with root access who wish to work on domains or sub-domains hosted by Plesk.


1. Script execution: best practices

  • Always run a script belonging to a user from the same user.
  • If you run a script directly from rootthe generated files will belong to root → which causes access rights problems.

Execute a command as a user

From root, two possibilities:

  • Open an interactive sessionthen run the commands directly :
sudo -iu username
  • Execute a single commandThis makes it easier to chain treatments over several users:
sudo -iu username command

👉 Important: rights are deliberately "lowered" from root to user.
Conversely, never give sudo rights to a single user on a web server (security risk and loss of isolation between domains).

2. PHP version management

SSH mechanism

On Plesk, each domain (or sub-domain) can have its own version of PHP.
When a user connects via SSH, an environment variable automatically sets the correct PHP version for him/her.

This is why it is necessary to use -i with sudo to correctly load its environment :

sudo -iu username php -v

Use a specific version

PHP executables are available in :

/opt/plesk/php/7.4/bin/php
/opt/plesk/php/8.1/bin/php
/opt/plesk/php/8.2/bin/php
/opt/plesk/php/8.3/bin/php
/opt/plesk/php/8.4/bin/php

Example: run PHP 7.4 for a given user :

sudo -iu username /opt/plesk/php/7.4/bin/php -v

3. Node.js management

Same logic as for PHP.
Examples of directories :

/opt/plesk/node/20/bin/node
/opt/plesk/node/22/bin/node
/opt/plesk/node/24/bin/node

Command from root to run Node with the user's environment:

sudo -iu username /opt/plesk/node/24/bin/node -v

4. Good shell practice

We recommend using /bin/bash as the default shell for service users, rather than /bin/shto avoid limitations or incompatibilities.

5. Safety reminder

  • Run from root with sudo -iu username is the recommended method.
  • Each user must remain isolated in its file.
  • Never turn a simple user into a sudoer.

✅ With these practices, you'll be able to serenely manage the execution of scripts and different versions of PHP/Node on your Plesk servers.

🤖 LRobot, your AI assistant