Running scripts and managing PHP/Node versions on Plesk servers

Updated on

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 PHP and Node versions available.
The goal is to ensure:

  • scripts run correctly without permission problems,
  • user environments are used consistently,
  • and optimal security by avoiding bad practices (such as giving sudo rights to ordinary users).

It is mainly intended for administrators with root access who want to work on domains or subdomains hosted under Plesk.


1. Running scripts: best practices

  • Always run a script that belongs to a user from that same user.
  • If you run a script directly from root, the files it generates will belong to root → which causes access permission problems.

Run a command as a user

From root, there are two options:

  • Open an interactive session, then run the commands directly:
sudo -iu username
  • Run a single command, more convenient for chaining operations across several users:
sudo -iu username commande

👉 Important: you deliberately “lower” privileges from root to the user.
Conversely, you must never give sudo rights to an ordinary user on a web server (security risk and loss of isolation between domains).

2. Managing PHP versions

Mechanism over SSH

On Plesk, each domain (or subdomain) can have its own PHP version.
When a user connects over SSH, an environment variable automatically sets the right PHP version for them.

This is why you need to use -i with sudo to load their environment correctly:

sudo -iu username php -v

Use a specific version

The 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. Managing Node.js

Same logic as for PHP.
Example 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. Shell best practices

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

5. Security reminder

  • Running from root with sudo -iu username is the recommended method.
  • Each user must remain isolated in their own folder.
  • Never turn an ordinary user into a sudoer.

✅ With these practices, you will be able to manage script execution and the different PHP/Node versions on your Plesk servers with peace of mind.