Answers.Body: <p>So, here was the problem and thanks to <a href="https://civicrm.stackexchange.com/users/12/jon-g-megaphone-tech">Jon G</a> for putting me on the track and explaining a few things. Amazon AWS Lightsail for WordPress (WP) allows you to SSH in from their terminal. In my case and I presume most of them, bitnami is the user. This is not to be confused with users in WordPress or CiviCRM. In my case, I set up a user in WP called xxx. I made the user a Subscriber in WP for security reasons. I then synced xxx to CiviCRM and assigned xxx to the Admin Group with Administrator privileges. After that, I went into the AWS SSH terminal and typed in crontab -e which allows you to edit the cron jobs. I entered the following: <code> */15 * * * * sudo /opt/bitnami/wp-cli/bin/wp --url=https://yourwebsite.com --path=/opt/bitnami/wordpress civicrm api job.execute auth=0 --user=xxxx &gt; /dev/null 2&gt;&amp;1</code></p>
  <p>What had been missing in my cron was the sudo command.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-25T22:53:45.720Z
Answers.Text: This is close to a good solution, but it's going to cause problems down the line.  If, for instance, your scheduled job sends a mailing, it will create files in the `templates_c` directory owned by `root`.  Cache clears won't be able to remove those, since they run as the PHP user and will lack file permissions.  At some point, you'll start seeing pages in Civi that are missing chunks.
  
  With SSH you can `cd` into the web directory and use `ls -l`, which should show you who owns the files. In most cases, you can just add `-u <username>` after sudo and you should be good.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-26T15:28:50.800Z
Answers.Text: Curious on this. So, the -u <username> after sudo is different than the --user towards the end? Also, every time I update, I am instructed to delete the templates_c as per the SysAdmin manual. '''bitnami@ip-xxx:~$ ls -l
  total 8
  -rw------- 1 bitnami bitnami  13 Sep  2 13:08 bitnami_application_password
  -r-------- 1 bitnami bitnami 430 Sep 20 18:30 bitnami_credentials
  lrwxrwxrwx 1 bitnami bitnami  27 Jul 24 13:51 htdocs -> /opt/bitnami/apache2/htdocs
  lrwxrwxrwx 1 bitnami bitnami  12 Jul 24 13:51 stack -> /opt/bitnami''' So, I presume that bitnami is the user you refer to.
Answers.UserDisplayName: Paul Williams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-26T15:30:11.117Z
Answers.Text: If bitnami is the main user, then when I add the cron and use sudo, does it not apply the sudo as bitnami? Thanx!
Answers.UserDisplayName: Paul Williams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-26T15:34:58.573Z
Answers.Text: this is no longer about CiviCRM and is more general sysadmin, so you may have better luck with other resources online, particularly those dealing with Unix-style file permissions and ownership.  But no - `--user` is an option of `wp` and refers to the WordPress user.  `sudo -u` is referring to the Unix user.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-25T18:29:00.833Z
Answers.LastActivityDate: 2024-09-25T18:29:00.833Z
Answers.UserDisplayName: Paul Williams
Body: <p>WordPress v6.6.2 CiviCRM v5.77.0 Amazon AWS Lightsail</p>
  <p>Using WP-CLI. Can manually trigger it, but it will not automate.</p>
  <p>Steps taken:</p>
  <p>crontab -e set as:</p>
  <pre><code>*/15 * * * * /opt/bitnami/wp-cli/bin/wp --path=/opt/bitnami/wordpress civicrm api job.execute --user=xxxx &gt;&gt; /opt/bitnami/cron_log.txt 2&gt;&amp;1   
  </code></pre>
  <p>Note that the user is an Admin in CiviCRM at all times as well as WordPress. It will trigger manually fine with Subscriber in WordPress and Admin in CiviCRM, though, which I like better for security.</p>
  <p>Triggers cron when I enter the below:</p>
  <pre><code>sudo /opt/bitnami/wp-cli/bin/wp --path=/opt/bitnami/wordpress civicrm api job.execute --user=xxxx
  </code></pre>
  <p>This is the result:</p>
  <pre><code>Processed as Activity: Re: Cron Program
  Array
  (
      [is_error] =&gt; 0
      [version] =&gt; 3
      [count] =&gt; 1
      [values] =&gt; 1
  )
  </code></pre>
  <p>I took the additional steps of even adding define('DISABLE_WP_CRON', true); to the civi.settings.php to no avail and then adding a cronjob to trigger the WordPress stuff as follows:</p>
  <p>Error shows last manual run by stating: Cron Not Running
  Last cron run at September 22nd, 2024 12:57 PM.
  A cron job is required to execute scheduled jobs automatically.</p>
  <p>A few notes here:</p>
  <p>which wp ... <code>/opt/bitnami/wp-cli/bin/wp</code></p>
  <pre><code>sudo wp --info
  OS:Linux 6.1.0-25-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x8
  6_64
  Shell:/bin/bash
  PHP binary:/opt/bitnami/php/bin/php
  PHP version:8.2.21
  php.ini used:/opt/bitnami/php/lib/php.ini
  MySQL binary:/opt/bitnami/mariadb/bin/mysql
  MySQL version:mysql from 11.4.2-MariaDB, client 15.2 for Linux (x86_64) using readline 5
  .1
  SQL modes:
  WP-CLI root dir:phar://wp-cli.phar/vendor/wp-cli/wp-cli
  WP-CLI vendor dir:phar://wp-cli.phar/vendor
  WP_CLI phar path:/home/bitnami
  WP-CLI packages dir:/opt/bitnami/wp-cli/.packages/
  WP-CLI cache dir:/opt/bitnami/wp-cli/.cache
  WP-CLI global config:/opt/bitnami/wp-cli/conf/wp-cli.yml
  WP-CLI project config:
  WP-CLI version:2.10.0
  </code></pre>
  <p>Modified to the below to run every minute with zero change:</p>
  <pre><code>*/1 * * * * /opt/bitnami/wp-cli/bin/wp --url=https://fighttheblightinc.com --path=/opt/bitnami/wordpress civicrm api job.execute auth=
  0 --user=xxxx &gt; /dev/null 2&gt;&amp;1
  </code></pre>
  <p>Any help appreciated!</p>
  <p>Notes requested added:</p>
  <p>Apache is running under the daemon user, and root is used to start the service. User being passed in the crontab is admin on both WP and CiviCRM. The PHP version is above and is 8.8.21. Permissions are: drwxrwxr-x 6 bitnami daemon 4096 Sep 23 20:00 /opt/bitnami/wordpress.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-23T17:15:35.733Z
Comments.Text: I just edited this for clarity - if you don't put your terminal output inside a code block (with triple backticks` then Stack Exchange removes the line breaks.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-23T17:18:21.753Z
Comments.Text: You mention `crontab -e` but don't specify which user you're running as when you run that command.  Could you please edit your question to a) include that, b) which user PHP is running as, c) confirm that the PHP user has read access to the site's filesystem?  You can use `chown -R` to set the permissions on the whole site at once.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-23T20:25:02.660Z
Comments.Text: Added requested notes in the edit. If you have specific commands you want run let me know. thx
Comments.UserDisplayName: Paul Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-24T03:14:41.133Z
Comments.Text: it's not the user for `wp`, it's the user that runs `crontab`.  Cron will run as that user.  So if your daemon user is `httpd`, you should run `sudo crontab -e -u httpd` to edit `httpd`'s crontab.  You can also run `sudo -u httpd <cv command>` to test as that user.
  
  If this doesn't work, please add a comment here so I'll get notified.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-24T14:44:17.757Z
Comments.Text: using httpd doesn't work: crontab:  user `httpd' unknown. Using bitnami does and simply does what crontab -e does and allows me to edit the exiting cron jobs reported in original post. The second sudo command, verbatim as I do not know what to put instead of <cv command>, returns: -bash: syntax error near unexpected token `newline' whether or not I use httpd or bitnami. Is my presumption that bitnami is the user correct going forward as I am at root level and capable of using sudo? thx
Comments.UserDisplayName: Paul Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-24T15:11:21.147Z
Comments.Text: FYI: This is the terminal: bitnami@ip-xxx-xx-xx-xx:~$
Comments.UserDisplayName: Paul Williams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-24T16:15:00.507Z
Comments.Text: Hi Paul - I'm losing the thread a bit here.  If user `httpd` is unknown, what is the name of the user that PHP runs as? But it sounds like you're setting the cron for the "bitnami" user when you should be setting the cron for the user PHP runs as.  And sorry - that should read `<wp command>`, not `<cv command>`, and it should be the same command you're using in cron now.
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <wordpress><cron><aws>
Title: Cron on AWS Lightsail
ThreadText: # Cron on AWS Lightsail
  
  (Asked by: username_0 on 2024-09-23)
  
  WordPress v6.6.2 CiviCRM v5.77.0 Amazon AWS Lightsail
  
  Using WP-CLI. Can manually trigger it, but it will not automate.
  
  Steps taken:
  
  crontab -e set as:
  
  ```
  */15 * * * * /opt/bitnami/wp-cli/bin/wp --path=/opt/bitnami/wordpress civicrm api job.execute --user=xxxx >> /opt/bitnami/cron_log.txt 2>&1   
  
  ```
  
  Note that the user is an Admin in CiviCRM at all times as well as WordPress. It will trigger manually fine with Subscriber in WordPress and Admin in CiviCRM, though, which I like better for security.
  
  Triggers cron when I enter the below:
  
  ```
  sudo /opt/bitnami/wp-cli/bin/wp --path=/opt/bitnami/wordpress civicrm api job.execute --user=xxxx
  
  ```
  
  This is the result:
  
  ```
  Processed as Activity: Re: Cron Program
  Array
  (
      [is_error] => 0
      [version] => 3
      [count] => 1
      [values] => 1
  )
  
  ```
  
  I took the additional steps of even adding define('DISABLE\_WP\_CRON', true); to the civi.settings.php to no avail and then adding a cronjob to trigger the WordPress stuff as follows:
  
  Error shows last manual run by stating: Cron Not Running
  Last cron run at September 22nd, 2024 12:57 PM.
  A cron job is required to execute scheduled jobs automatically.
  
  A few notes here:
  
  which wp ... `/opt/bitnami/wp-cli/bin/wp`
  
  ```
  sudo wp --info
  OS:Linux 6.1.0-25-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x8
  6_64
  Shell:/bin/bash
  PHP binary:/opt/bitnami/php/bin/php
  PHP version:8.2.21
  php.ini used:/opt/bitnami/php/lib/php.ini
  MySQL binary:/opt/bitnami/mariadb/bin/mysql
  MySQL version:mysql from 11.4.2-MariaDB, client 15.2 for Linux (x86_64) using readline 5
  .1
  SQL modes:
  WP-CLI root dir:phar://wp-cli.phar/vendor/wp-cli/wp-cli
  WP-CLI vendor dir:phar://wp-cli.phar/vendor
  WP_CLI phar path:/home/bitnami
  WP-CLI packages dir:/opt/bitnami/wp-cli/.packages/
  WP-CLI cache dir:/opt/bitnami/wp-cli/.cache
  WP-CLI global config:/opt/bitnami/wp-cli/conf/wp-cli.yml
  WP-CLI project config:
  WP-CLI version:2.10.0
  
  ```
  
  Modified to the below to run every minute with zero change:
  
  ```
  */1 * * * * /opt/bitnami/wp-cli/bin/wp --url=https://fighttheblightinc.com --path=/opt/bitnami/wordpress civicrm api job.execute auth=
  0 --user=xxxx > /dev/null 2>&1
  
  ```
  
  Any help appreciated!
  
  Notes requested added:
  
  Apache is running under the daemon user, and root is used to start the service. User being passed in the crontab is admin on both WP and CiviCRM. The PHP version is above and is 8.8.21. Permissions are: drwxrwxr-x 6 bitnami daemon 4096 Sep 23 20:00 /opt/bitnami/wordpress.
  
  **Tags:** wordpress, cron, aws
  
  > **Comments:**
  > **username_1**: I just edited this for clarity - if you don't put your terminal output inside a code block (with triple backticks` then Stack Exchange removes the line breaks.  
  > **username_1**: You mention `crontab -e` but don't specify which user you're running as when you run that command.  Could you please edit your question to a) include that, b) which user PHP is running as, c) confirm that the PHP user has read access to the site's filesystem?  You can use `chown -R` to set the permissions on the whole site at once.  
  > **username_0**: Added requested notes in the edit. If you have specific commands you want run let me know. thx  
  > **username_1**: it's not the user for `wp`, it's the user that runs `crontab`.  Cron will run as that user.  So if your daemon user is `httpd`, you should run `sudo crontab -e -u httpd` to edit `httpd`'s crontab.  You can also run `sudo -u httpd <cv command>` to test as that user.  If this doesn't work, please add a comment here so I'll get notified.  
  > **username_0**: using httpd doesn't work: crontab:  user `httpd' unknown. Using bitnami does and simply does what crontab -e does and allows me to edit the exiting cron jobs reported in original post. The second sudo command, verbatim as I do not know what to put instead of <cv command>, returns: -bash: syntax error near unexpected token `newline' whether or not I use httpd or bitnami. Is my presumption that bitnami is the user correct going forward as I am at root level and capable of using sudo? thx  
  > **username_0**: FYI: This is the terminal: bitnami@ip-xxx-xx-xx-xx:~$  
  > **username_1**: Hi username_0 - I'm losing the thread a bit here.  If user `httpd` is unknown, what is the name of the user that PHP runs as? But it sounds like you're setting the cron for the "bitnami" user when you should be setting the cron for the user PHP runs as.  And sorry - that should read `<wp command>`, not `<cv command>`, and it should be the same command you're using in cron now.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-09-25. Score: 2 | Accepted answer
  
  So, here was the problem and thanks to [Jon G](https://civicrm.stackexchange.com/users/12/jon-g-megaphone-username_1) for putting me on the track and explaining a few things. Amazon AWS Lightsail for WordPress (WP) allows you to SSH in from their terminal. In my case and I presume most of them, bitnami is the user. This is not to be confused with users in WordPress or CiviCRM. In my case, I set up a user in WP called xxx. I made the user a Subscriber in WP for security reasons. I then synced xxx to CiviCRM and assigned xxx to the Admin Group with Administrator privileges. After that, I went into the AWS SSH terminal and typed in crontab -e which allows you to edit the cron jobs. I entered the following:  `*/15 * * * * sudo /opt/bitnami/wp-cli/bin/wp --url=https://yourwebsite.com --path=/opt/bitnami/wordpress civicrm api job.execute auth=0 --user=xxxx > /dev/null 2>&1`
  
  What had been missing in my cron was the sudo command.
  
  > **Comments:**
  > **username_1**: This is close to a good solution, but it's going to cause problems down the line.  If, for instance, your scheduled job sends a mailing, it will create files in the `templates_c` directory owned by `root`.  Cache clears won't be able to remove those, since they run as the PHP user and will lack file permissions.  At some point, you'll start seeing pages in Civi that are missing chunks.  With SSH you can `cd` into the web directory and use `ls -l`, which should show you who owns the files. In most cases, you can just add `-u <username>` after sudo and you should be good.  
  > **username_0**: Curious on this. So, the -u <username> after sudo is different than the --user towards the end? Also, every time I update, I am instructed to delete the templates_c as per the SysAdmin manual. '''bitnami@ip-xxx:~$ ls -l total 8 -rw------- 1 bitnami bitnami  13 Sep  2 13:08 bitnami_application_password -r-------- 1 bitnami bitnami 430 Sep 20 18:30 bitnami_credentials lrwxrwxrwx 1 bitnami bitnami  27 Jul 24 13:51 htdocs -> /opt/bitnami/apache2/htdocs lrwxrwxrwx 1 bitnami bitnami  12 Jul 24 13:51 stack -> /opt/bitnami''' So, I presume that bitnami is the user you refer to.  
  > **username_0**: If bitnami is the main user, then when I add the cron and use sudo, does it not apply the sudo as bitnami? Thanx!  
  > **username_1**: this is no longer about CiviCRM and is more general sysadmin, so you may have better luck with other resources online, particularly those dealing with Unix-style file permissions and ownership.  But no - `--user` is an option of `wp` and refers to the WordPress user.  `sudo -u` is referring to the Unix user.  
  
  ---
  
  