Answers.Body: <p>As I looked at it more and how php does environment variables; I discovered the thing that was different was the system $PATH variable.</p>
  <p>In bash on linux; this is what sets the search order for trying to find executables like php and composer.</p>
  <p>Run <code>php -i</code> from an command prompt and bash is search for an executable &quot;php&quot; in every folder of PATH. Note it stops when it finds the first match so the order of things in PATH is important.</p>
  <p>So my problem is really that when craft runs a shell command; php/composer aren't in PATH.</p>
  <p>putenv() does exactly that; allows php to set an environment variable for the duration of scrip execution. The very excellent dotenv library that craft depends on makes use of that.</p>
  <p>The scl command line tools (source and scl) change PATH. Once I saw the expected values it was as simple as popping those over into the .env file for my site.</p>
  <p>I added a <code>PATH=&quot;/opt/rh/rh-php73/root/usr/bin:/opt/rh/rh-mysql56/root/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin&quot;</code>
  to the top of my sites .env file. (usually in the SITEROOT/craft/ folder)
  and now updates succeed and database backups work too.</p>
  <p>If you're using mamp or any other awkward environment where php isn't in the system path; this would likely work for you too.</p>
  <p>Take note that variables set in a .env file WILL NOT overwrite an existing variable.
  <a href="https://github.com/vlucas/phpdotenv/tree/3.6#immutability" rel="nofollow noreferrer">https://github.com/vlucas/phpdotenv/tree/3.6#immutability</a>
  a small change to your craft/web/index.php file is needed to change that behavior.</p>
  <p>Change</p>
  <p><code>Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();</code></p>
  <p>to</p>
  <p><code>Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;overload();</code></p>
  <p>and then any settings in your .env file will be honored even if they already existing in the environment.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-08T21:49:25.003Z
Answers.LastActivityDate: 2021-05-14T21:01:03.440Z
Answers.LastEditDate: 2021-05-14T21:01:03.440Z
Answers.UserDisplayName: Derak
Body: <p>Is it possible to configure the PATH to composer that craft is using?</p>
  <p>In a shared hosting (our server, lots of sites) php isn't available by default.
  It's provided via redhat software collections. Each site can choose which version to run via environment variables. Since craft also uses composer; it means updates via it's web ui fail because when craft shells out to run composer; its not selecting which php it wants.</p>
  
Tags: <server><composer><environmentvariables>
Title: Configure path craft uses for composer and php
ThreadText: # Configure path craft uses for composer and php
  
  (Asked by: username_0 on 2021-03-08)
  
  Is it possible to configure the PATH to composer that craft is using?
  
  In a shared hosting (our server, lots of sites) php isn't available by default.
  It's provided via redhat software collections. Each site can choose which version to run via environment variables. Since craft also uses composer; it means updates via it's web ui fail because when craft shells out to run composer; its not selecting which php it wants.
  
  **Tags:** server, composer, environmentvariables
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-03-08. Score: 1 | Accepted answer
  
  As I looked at it more and how php does environment variables; I discovered the thing that was different was the system $PATH variable.
  
  In bash on linux; this is what sets the search order for trying to find executables like php and composer.
  
  Run `php -i` from an command prompt and bash is search for an executable "php" in every folder of PATH. Note it stops when it finds the first match so the order of things in PATH is important.
  
  So my problem is really that when craft runs a shell command; php/composer aren't in PATH.
  
  putenv() does exactly that; allows php to set an environment variable for the duration of scrip execution. The very excellent dotenv library that craft depends on makes use of that.
  
  The scl command line tools (source and scl) change PATH. Once I saw the expected values it was as simple as popping those over into the .env file for my site.
  
  I added a `PATH="/opt/rh/rh-php73/root/usr/bin:/opt/rh/rh-mysql56/root/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"`
  to the top of my sites .env file. (usually in the SITEROOT/craft/ folder)
  and now updates succeed and database backups work too.
  
  If you're using mamp or any other awkward environment where php isn't in the system path; this would likely work for you too.
  
  Take note that variables set in a .env file WILL NOT overwrite an existing variable.
  <https://github.com/vlucas/phpdotenv/tree/3.6#immutability>
  a small change to your craft/web/index.php file is needed to change that behavior.
  
  Change
  
  `Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load();`
  
  to
  
  `Dotenv\Dotenv::create(CRAFT_BASE_PATH)->overload();`
  
  and then any settings in your .env file will be honored even if they already existing in the environment.
  
  
  ---
  
  