Answers.Body: <p>The problem here was $civicrm_root being set in civicrm.settings.php based on an environment variable, which wasn't set during cron.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-21T03:14:11.050Z
Answers.LastActivityDate: 2024-01-21T03:14:11.050Z
Answers.UserDisplayName: Demerit
Body: <p>I am having an issue in Amazon Linux 2 where I can run cv commands from the command line but I cannot run cv commands from cron.</p>
  <p>For example:</p>
  <pre><code>/usr/bin/php /usr/local/bin/cv  api job.execute --user=cronusersupport --cwd=/var/app/current
  </code></pre>
  <p>This command will run perfectly from the command line using the default ec2-user account.
  Running this command from cron while logged in as the same user will produce:</p>
  <pre><code>In civicrm.settings.php line 569:
  
    [Error]
    Failed opening required 'CRM/Core/ClassLoader.php' (include_path='.::/packa
    ges:.:/usr/share/php:/usr/share/pear')
  </code></pre>
  <p>I have been logging the output to a file. So my actual crontab looks like this:</p>
  <pre><code>*/15 * * * * /usr/bin/php /usr/local/bin/cv  api job.execute --user=cronusersupport --cwd=/var/app/current -vvv &gt;&gt; /opt/paao_civi_cron.txt 2&gt;&amp;1
  </code></pre>
  <p>I have even tried adding <code>cd /var/app/current &amp;&amp;</code> before this command to make sure the command is running from the correct place.</p>
  <p>I have checked the verbose output and the last step that works correctly is <code>[Bootstrap:debug] Load settings file &quot;/var/app/current/web/sites/default/civicrm.settings.php&quot;</code>.</p>
  <p>I have worked with AWS support on this and we tried things like making sure my $PATH was correct,  running the command as an sh script,  trying to run as the webapp user who owns the files,  and I have even added the $civicrm_root to line 569 of civicrm.settings.php to see if that would work.</p>
  <p>I have the following config:</p>
  <p>EC2 instance with remote RDS server. The server is running well for HTTP requests and cv commands when not run from cron.</p>
  <p>Drupal -  9.5</p>
  <p>CiviCRM -5.64.4</p>
  <p>CV - 0.3.48</p>
  <p>PHP - 8.0.30</p>
  <p>If anyone has any ideas I would be very thankful as I am at a loss here.</p>
  <p>I have the same setup working on Ubuntu and it is working perfectly.</p>
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-15T07:51:15.047Z
Comments.Text: How have you defined civicrm_root in civicrm.settings.php? It seems like it's blank.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-17T08:33:02.263Z
Comments.Text: @Demerit, $civicrm_root is set to /var/app/current/vendor/civicrm/civicrm-core - thanks for your help!
Comments.UserDisplayName: Steve
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-17T20:35:08.983Z
Comments.Text: Sorry I double checked and to clarify that there is a / at the end (/var/app/current/vendor/civicrm/civicrm-core/).  Thanks!
Comments.UserDisplayName: Steve
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-18T17:19:34.967Z
Comments.Text: The reason I'm asking is because if you look at [the lines](https://github.com/civicrm/civicrm-core/blob/fbf738ed82313a0d6a3e5b873503244e82baf373/templates/CRM/common/civicrm.settings.php.template#L612) where it sets the include_path, your include_path looks exactly like what it would look like if $civicrm_root was blank. Is there maybe a second place in the file where it's blanking out $civicrm_root?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-18T21:40:32.393Z
Comments.Text: @Demerit, I will do another analysis but that appears unlikely to me because the command runs from the command line just not from cron. If the variable was bank then I would think it would break in all cases.
Comments.UserDisplayName: Steve
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-18T21:55:03.757Z
Comments.Text: If you had a line like `$civicrm_root=$_ENV['something'];` then it's possible that might work from your login shell but come out blank during cron.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-19T23:07:52.483Z
Comments.Text: @Demerit, you hit it right on the nose. Thank you!!
Comments.UserDisplayName: Steve
Tags: <cron><cron-job><cv>
Title: CV Does Not Work From Cron
ThreadText: # CV Does Not Work From Cron
  
  (Asked by: username_0 on 2024-01-15)
  
  I am having an issue in Amazon Linux 2 where I can run cv commands from the command line but I cannot run cv commands from cron.
  For example:
  /usr/bin/php /usr/local/bin/cv  api job.execute --user=cronusersupport --cwd=/var/app/current
  
  This command will run perfectly from the command line using the default ec2-user account.
  Running this command from cron while logged in as the same user will produce:
  In civicrm.settings.php line 569:
  
    [Error]
    Failed opening required 'CRM/Core/ClassLoader.php' (include_path='.::/packa
    ges:.:/usr/share/php:/usr/share/pear')
  
  I have been logging the output to a file. So my actual crontab looks like this:
  */15 * * * * /usr/bin/php /usr/local/bin/cv  api job.execute --user=cronusersupport --cwd=/var/app/current -vvv >> /opt/paao_civi_cron.txt 2>&1
  
  I have even tried adding cd /var/app/current && before this command to make sure the command is running from the correct place.
  I have checked the verbose output and the last step that works correctly is [Bootstrap:debug] Load settings file "/var/app/current/web/sites/default/civicrm.settings.php".
  I have worked with AWS support on this and we tried things like making sure my $PATH was correct,  running the command as an sh script,  trying to run as the webapp user who owns the files,  and I have even added the $civicrm_root to line 569 of civicrm.settings.php to see if that would work.
  I have the following config:
  EC2 instance with remote RDS server. The server is running well for HTTP requests and cv commands when not run from cron.
  Drupal -  9.5
  CiviCRM -5.64.4
  CV - 0.3.48
  PHP - 8.0.30
  If anyone has any ideas I would be very thankful as I am at a loss here.
  I have the same setup working on Ubuntu and it is working perfectly.
  Thanks!
  
  **Tags:** cron, cron-job, cv
  
  > **Comments:**
  > **username_1**: How have you defined civicrm_root in civicrm.settings.php? It seems like it's blank.  
  > **username_0**: @username_1, $civicrm_root is set to /var/app/current/vendor/civicrm/civicrm-core - thanks for your help!  
  > **username_0**: Sorry I double checked and to clarify that there is a / at the end (/var/app/current/vendor/civicrm/civicrm-core/).  Thanks!  
  > **username_1**: The reason I'm asking is because if you look at [the lines](https://github.com/civicrm/civicrm-core/blob/fbf738ed82313a0d6a3e5b873503244e82baf373/templates/CRM/common/civicrm.settings.php.template#L612) where it sets the include_path, your include_path looks exactly like what it would look like if $civicrm_root was blank. Is there maybe a second place in the file where it's blanking out $civicrm_root?  
  > **username_0**: @username_1, I will do another analysis but that appears unlikely to me because the command runs from the command line just not from cron. If the variable was bank then I would think it would break in all cases.  
  > **username_1**: If you had a line like `$civicrm_root=$_ENV['something'];` then it's possible that might work from your login shell but come out blank during cron.  
  > **username_0**: @username_1, you hit it right on the nose. Thank you!!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-01-21. Score: 1 | Accepted answer
  
  The problem here was $civicrm\_root being set in civicrm.settings.php based on an environment variable, which wasn't set during cron.
  
  
  ---
  
  