Answers.Body: <p>This cron job calls <code>/etc/php.ini</code> as the command, but that file is not an executable (it's the default configuration file for PHP).</p>
  
  <p>(The "Permission denied" error is the same as if you asked "run the script README.TXT" - the file doesn't have exec bit set because it's not a program at all.)</p>
  
  <p>Try this -</p>
  
  <pre><code>1 * * * * apache /usr/bin/php /var/www/example.org/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser-cron -p wordpresspasswordhere -e Job -a execute
  </code></pre>
  
  <p>Your PHP path may not actually be <code>/usr/bin/php</code>, so check the correct path by typing <code>which php</code> at a commandline and use that.</p>
  
  <hr>
  
  <blockquote>
    <p>Running it as the user apache definitely seems wrong.</p>
  </blockquote>
  
  <p>This is OK. It means that CiviCRM when executed from cron and from the web will generate files using the same user - CiviCRM can have issues when it hits file access issues between multiple users, so using a single user for both www and cron is the simplest solution.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-13T20:01:24.457Z
Answers.Text: I'm not sure how I had the ini file in the command. I corrected it with php, added a user to apache group and the command ran fine. Adding the final crontab for reference -  15 *  *  *  * <systemuser> php /var/www/domainfolder/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser -p wppasswordhere -e Job -a execute
Answers.UserDisplayName: eauxnguyen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-13T20:03:43.987Z
Answers.Text: I can't see the rest of your comment, but: running both cron and www as apache is the simplest configuration. It has issues (eg if there are other sites on the same host), but doing anything more advanced will require a deeper understanding of UNIX permissions. Your new user AND the apache user will both need to have default ownership and permissions which share nicely between the two accounts.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-13T20:11:14.880Z
Answers.Text: Sorry I was mid edit and surprised at the lack of line breaks in comments. It's not on a shared host server. By adding the user to the same group as the apache user I was able to get this working. Thanks for your attention to this question. I appreciate it.
Answers.UserDisplayName: eauxnguyen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-13T19:55:36.313Z
Answers.LastActivityDate: 2016-08-13T19:55:36.313Z
Answers.UserDisplayName: Chris Burgess
Body: <p>Centos 7 with selinux set to permissive. Using apache as the user and confirmed apache has execute permissions to the folder and file in plugins/civicrm/civicrm/bin/cli.php</p>
  
  <p>The crontab entry -</p>
  
  <pre><code>1 * * * * apache /etc/php.ini var/www/domainfolder/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser-cron -p wordpresspasswordhere -e Job -a execute
  </code></pre>
  
  <p>The error generated is -</p>
  
  <pre><code>X-Cron-Env: &lt;SHELL=/bin/bash&gt;
  X-Cron-Env: &lt;PATH=/sbin:/bin:/usr/sbin:/usr/bin&gt;
  X-Cron-Env: &lt;MAILTO=root&gt;
  X-Cron-Env: &lt;HOME=/usr/share/httpd&gt;
  X-Cron-Env: &lt;LOGNAME=apache&gt;
  X-Cron-Env: &lt;USER=apache&gt;
  Date: Fri, 12 Aug 2016 15:01:01 -0400 (EDT)
  Status: RO
  
  /bin/bash: /etc/php.ini: Permission denied
  </code></pre>
  
  <p>Running it as the user apache definitely seems wrong. I did so just to see that I could get the cron job running properly; then revisit selinux settings to deal with creating a group with the correct permissions and a cron user for this job. </p>
  
Tags: <php><cron><cli>
Title: Configuring cron using PHP cli method results in Permission denied
ThreadText: # Configuring cron using PHP cli method results in Permission denied
  
  (Asked by: username_0 on 2016-08-13)
  
  Centos 7 with selinux set to permissive. Using apache as the user and confirmed apache has execute permissions to the folder and file in plugins/civicrm/civicrm/bin/cli.php
  The crontab entry -
  1 * * * * apache /etc/php.ini var/www/domainfolder/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser-cron -p wordpresspasswordhere -e Job -a execute
  
  The error generated is -
  X-Cron-Env: 
  X-Cron-Env: 
  X-Cron-Env: 
  X-Cron-Env: 
  X-Cron-Env: 
  X-Cron-Env: 
  Date: Fri, 12 Aug 2016 15:01:01 -0400 (EDT)
  Status: RO
  
  /bin/bash: /etc/php.ini: Permission denied
  
  Running it as the user apache definitely seems wrong. I did so just to see that I could get the cron job running properly; then revisit selinux settings to deal with creating a group with the correct permissions and a cron user for this job.
  
  **Tags:** php, cron, cli
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-13. Score: 1 | Accepted answer
  
  This cron job calls /etc/php.ini as the command, but that file is not an executable (it's the default configuration file for PHP).
  (The "Permission denied" error is the same as if you asked "run the script README.TXT" - the file doesn't have exec bit set because it's not a program at all.)
  Try this -
  1 * * * * apache /usr/bin/php /var/www/example.org/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser-cron -p wordpresspasswordhere -e Job -a execute
  
  Your PHP path may not actually be /usr/bin/php, so check the correct path by typing which php at a commandline and use that.
  
  
  Running it as the user apache definitely seems wrong.
  
  This is OK. It means that CiviCRM when executed from cron and from the web will generate files using the same user - CiviCRM can have issues when it hits file access issues between multiple users, so using a single user for both www and cron is the simplest solution.
  
  > **Comments:**
  > **username_0**: I'm not sure how I had the ini file in the command. I corrected it with php, added a user to apache group and the command ran fine. Adding the final crontab for reference -  15 *  *  *  * <systemuser> php /var/www/domainfolder/public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s domain.com -u wpuser -p wppasswordhere -e Job -a execute  
  > **username_1**: I can't see the rest of your comment, but: running both cron and www as apache is the simplest configuration. It has issues (eg if there are other sites on the same host), but doing anything more advanced will require a deeper understanding of UNIX permissions. Your new user AND the apache user will both need to have default ownership and permissions which share nicely between the two accounts.  
  > **username_0**: Sorry I was mid edit and surprised at the lack of line breaks in comments. It's not on a shared host server. By adding the user to the same group as the apache user I was able to get this working. Thanks for your attention to this question. I appreciate it.  
  
  ---
  
  