{"id":8341,"date":"2025-09-20T00:10:54","date_gmt":"2025-09-19T22:10:54","guid":{"rendered":"https:\/\/www.lrob.fr\/?page_id=8341"},"modified":"2025-09-21T16:47:18","modified_gmt":"2025-09-21T14:47:18","slug":"cli-script-execution","status":"publish","type":"page","link":"https:\/\/www.lrob.fr\/en\/doc\/documentation-serveurs-plesk-infogeres\/execution-de-scripts-cli\/","title":{"rendered":"Script execution and PHP\/Node version management on Plesk servers"},"content":{"rendered":"<p>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.<br>The aim is to guarantee :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>correct script execution without permissions problems,<\/li>\n\n\n\n<li>consistent use of user environments,<\/li>\n\n\n\n<li>and optimal security by avoiding bad practices (such as giving sudo rights to simple users).<\/li>\n<\/ul>\n\n\n\n<p>It is primarily aimed at administrators with root access who wish to work on domains or sub-domains hosted by Plesk.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. Script execution: best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always run a script belonging to a <strong>user<\/strong> from the same <strong>user<\/strong>.<\/li>\n\n\n\n<li>If you run a script directly from <strong>root<\/strong>the generated files will belong to root \u2192 which causes access rights problems.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Execute a command as a user<\/h3>\n\n\n\n<p>From root, two possibilities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Open an interactive session<\/strong>then run the commands directly :<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -iu username<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Execute a single command<\/strong>This makes it easier to chain treatments over several users:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -iu username command<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49 Important: rights are deliberately \"lowered\" from root to user.<br>Conversely, never give sudo rights to a single user on a web server (security risk and loss of isolation between domains).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP version management<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">SSH mechanism<\/h3>\n\n\n\n<p>On Plesk, each domain (or sub-domain) can have its own version of PHP.<br>When a user connects via SSH, an environment variable automatically sets the correct PHP version for him\/her.<\/p>\n\n\n\n<p>This is why it is necessary to use <code>-i<\/code> with <code>sudo<\/code> to correctly load its environment :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -iu username php -v<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Use a specific version<\/h3>\n\n\n\n<p>PHP executables are available in :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/plesk\/php\/7.4\/bin\/php\n\/opt\/plesk\/php\/8.1\/bin\/php\n\/opt\/plesk\/php\/8.2\/bin\/php\n\/opt\/plesk\/php\/8.3\/bin\/php\n\/opt\/plesk\/php\/8.4\/bin\/php<\/code><\/pre>\n\n\n\n<p>Example: run PHP 7.4 for a given user :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -iu username \/opt\/plesk\/php\/7.4\/bin\/php -v<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Node.js management<\/h2>\n\n\n\n<p>Same logic as for PHP.<br>Examples of directories :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/plesk\/node\/20\/bin\/node\n\/opt\/plesk\/node\/22\/bin\/node\n\/opt\/plesk\/node\/24\/bin\/node<\/code><\/pre>\n\n\n\n<p>Command from root to run Node with the user's environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -iu username \/opt\/plesk\/node\/24\/bin\/node -v<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Good shell practice<\/h2>\n\n\n\n<p>We recommend using <strong>\/bin\/bash<\/strong> as the default shell for service users, rather than <strong>\/bin\/sh<\/strong>to avoid limitations or incompatibilities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Safety reminder<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Run from root with <code>sudo -iu username<\/code> is the recommended method.<\/li>\n\n\n\n<li>Each user must remain <strong>isolated in its file<\/strong>.<\/li>\n\n\n\n<li>Never turn a simple user into a sudoer.<\/li>\n<\/ul>\n\n\n\n<p>\u2705 With these practices, you'll be able to serenely manage the execution of scripts and different versions of PHP\/Node on your Plesk servers.<\/p>","protected":false},"excerpt":{"rendered":"<p>Cette documentation pr\u00e9sente les bonnes pratiques pour ex\u00e9cuter des scripts en CLI (lignes de commande) sur un serveur Plesk en environnement multi-users, ainsi que la gestion des diff\u00e9rentes versions de PHP et Node disponibles.L\u2019objectif est de garantir : Elle s\u2019adresse principalement aux administrateurs ayant acc\u00e8s root, qui souhaitent intervenir sur des domaines ou sous-domaines h\u00e9berg\u00e9s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":926,"parent":8337,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-8341","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/pages\/8341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/comments?post=8341"}],"version-history":[{"count":4,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/pages\/8341\/revisions"}],"predecessor-version":[{"id":8345,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/pages\/8341\/revisions\/8345"}],"up":[{"embeddable":true,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/pages\/8337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/media\/926"}],"wp:attachment":[{"href":"https:\/\/www.lrob.fr\/en\/wp-json\/wp\/v2\/media?parent=8341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}