Answers.Body: <p>And after all that, it looks like it was a password error after all, just not the password I thought.</p>
  
  <p>cli.php is retrieving the Drupal MySQL username and password from CIVICRM_UF_DSN in civicrm.settings.php as Jon G suggested. The instructions in that file say 'If any of these contain a single quote or backslash, escape those characters with a backslash: \' and \, respectively.' My password contained a double quote, and whichever script had generated that file put a backslash before the double quote: \". Taking the slash out seems to let the command run fine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-11T13:31:32.520Z
Answers.Text: This sounds like a bug to me. Follow these steps to report it: https://civicrm.org/bug-reporting. Thanks!
Answers.UserDisplayName: William Mortada
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T15:39:03.513Z
Answers.LastActivityDate: 2018-07-10T15:39:03.513Z
Answers.UserDisplayName: somnolentsurfer
Answers.Body: <p>First, you can view the error with greater detail if you enable "Debug and Backtrace", or view the CiviCRM log.  The <a href="https://docs.civicrm.org/sysadmin/en/latest/troubleshooting/" rel="nofollow noreferrer">troubleshooting documentation</a> will tell you how to do both.</p>
  
  <p>Second, I would assume that "connect failed" is a MySQL error.  Is it possible that you have two <code>civicrm.settings.php</code> files in your path, one with the wrong MySQL password?</p>
  
  <p>Finally - yes, <code>drush</code> and <code>cv</code> are additional tools to install.  However, if you're administering Drupal/CiviCRM through SSH, these tools are amazing timesavers.  Configuring cron with cv or drush is 10 times easier than what you're doing here, even if you factor in the overhead of installing drush or cv.  Drush in particular will give you a number of other command-line superpowers - you'll be glad you installed it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T10:22:02.323Z
Answers.Text: Sorry, first chance to test things after the weekend. Thank you.
  
  As far as I can see I only have one civicrm.settings.php file, in /<drupalroot>/sites/default. I do have a settings.php and a default.settings.php, if that makes any difference?
Answers.UserDisplayName: somnolentsurfer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T10:41:54.667Z
Answers.Text: Sorry, not getting my head around this comment system exactly. I've added what I found in the logs to the original post. Will go an have another look at Drush, but I was finding the documentation somewhat unhelpful!
Answers.UserDisplayName: somnolentsurfer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-06T20:08:22.833Z
Answers.LastActivityDate: 2018-07-06T20:08:22.833Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>I was also going to add that there are alternatives, e.g. CiviHosting offer this method which can be done via the hosting control panel <a href="https://civihosting.com/blog/how-to-make-a-cron-job-for-civicrm/" rel="nofollow noreferrer">https://civihosting.com/blog/how-to-make-a-cron-job-for-civicrm/</a></p>
  
  <p>And then you can also use an extension to use the Drupal cron to trigger the CiviCRM cron: 
  <a href="https://civicrm.org/extensions/civicrm-cron" rel="nofollow noreferrer">https://civicrm.org/extensions/civicrm-cron</a></p>
  
  <p>Not quite as satisfying as figuring it out via the SSH route but if you've tried several times and to no avail, this might just get it going for you.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T11:16:29.707Z
Answers.Text: Thanks. Both the options in that CiviHosting document seem to require having either the CLI or HTTP method working to start with though, which are both failing for me. Are there instructions anywhere on how to install that CiviCRM Cron module? 'Cause I'm getting an error using the standard Drupal Install new module link.
Answers.UserDisplayName: somnolentsurfer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T13:31:34.610Z
Answers.Text: @somnolentsurfer what's the error message when you're installing the module? Have you tried to upload and decompress it directly into the File Manager?
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T13:39:37.560Z
Answers.Text: Looking at your logs, just to clarify, does drupal_database_user refer to the MySQL user or a user in the Drupal frontend? It's the latter that you need to use to run the cron.
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T13:56:07.217Z
Answers.Text: The username that's coming back denied in the error message is the MySQL user. But the username I'm submitting through either cli or chron.php is a Drupal user I created exclusively for this purpose.
Answers.UserDisplayName: somnolentsurfer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T14:14:04.173Z
Answers.Text: Ah ha! I've uploaded the uncompressed CiviCRM Cron directly into `/<drupalroot>/sites/all/modules` and it seems to be working! I didn't notice at first because the configuration link didn't seem to appear until I refreshed the modules list after enabling it. The video linked on the extension page suggests that it's not really suitable for production sites, but it's five years old. Is that still true? Sorry, like I said, complete newbie!
Answers.UserDisplayName: somnolentsurfer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-10T20:36:27.563Z
Answers.Text: Hurrah! Glad it's all come together - all I know is that a CiviCRM implementer near me currently uses it for live sites. You'll just have to use it and see - if anything isn't working properly, disable the cron in case that's causing issues.
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-06T20:30:36.950Z
Answers.LastActivityDate: 2018-07-06T20:30:36.950Z
Answers.UserDisplayName: Rose Lanigan
Body: <p>I've set up a new CiviCRM install on a new Drupal install and I'm trying to configure Cron using the instructions at <a href="https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/" rel="nofollow noreferrer">https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/</a>.</p>
  
  <p>I'm a complete newbie at both CiviCRM and Drupal, and both the cv and Drush methods look like they need extra tools installed, so I've gone with the cli.php method.</p>
  
  <p>I'm logged in to my host using SSH and using the command from the manual (obviously completed with the paths, domain, and credentials for my site):</p>
  
  <pre><code>$ /path/to/php /path/to/civcrm/bin/cli.php \
    -s example.org \
    -u myusername \
    -p mypassword \
    -e Job \
    -a execute
  </code></pre>
  
  <p>That returns a bunch of HTML, obviously designed to be shown in a browser not a terminal, in which the only recognisable error message is 'DB Error: connect failed'.</p>
  
  <p>Can anyone tell me what I'm doing wrong?</p>
  
  <p><strong>Edit:</strong> OK, so I've tested getting the password wrong and that gets the same error, so I guess it's possible that I have a credentials problem of some kind. But I'm using the username and password of a Drupal administrator user that works just fine logging into the CMS via a browser.</p>
  
  <p>The only other thing I can think is that I think my file installation and my database are on different servers. But I filled in all those details when installing Drupal/CiviCRM and I don't see any errors in the GUI. Do I need to manually edit a script somewhere?</p>
  
  <p><strong>Further Edit:</strong> Still without joy, I gave up on the cli.php method and tried the HTTP method documented on the same page above. Trying to open the following URL in a browser results in exactly the same error, though obviously presented properly instead of raw HTML.</p>
  
  <pre><code>http://&lt;siteurl&gt;/sites/all/modules/civicrm/bin/cron.php?name=&lt;username&gt;&amp;pass=&lt;password&gt;&amp;key=&lt;sitekey&gt;
  </code></pre>
  
  <p><a href="https://i.sstatic.net/cx7ix.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cx7ix.png" alt="Screenshot of error in a browser"></a></p>
  
  <p>Can that narrow down the source of the problem at all?</p>
  
  <p><strong>Yet Further Edit:</strong> Looking in the logs I see the following:</p>
  
  <pre><code>[code] =&gt; -24
  [message] =&gt; DB Error: connect failed
  [mode] =&gt; 16
  [debug_info] =&gt;  [nativecode=Access denied for user '&lt;drupal_database_user&gt;'@'&lt;database_ip&gt;' (using password: YES)]
  [type] =&gt; DB_Error
  [user_info] =&gt;  [nativecode=Access denied for user '&lt;drupal_database_user&gt;'@'&lt;database_ip&gt;' (using password: YES)]
  [to_string] =&gt; [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::handle prefix="" info=" [nativecode=Access denied for user '&lt;drupal_database_user&gt;'@'&lt;database_ip&gt;' (using password: YES)]"]
  </code></pre>
  
  <p>I was surprised to see that it seems to be trying to connect with the user I had set up for the Drupal database, rather than the user for the CiviCRM database. That user originally only had Select access to the CiviCRM database. I've now given both users full access to both databases (which instinctively feels like a non-ideal setup?), but I'm still getting the same error.</p>
  
Tags: <drupal><installation><cron><scheduled-job>
Title: DB Error: connect failed when trying to call Job.execute using cli.php?
ThreadText: # DB Error: connect failed when trying to call Job.execute using cli.php?
  
  (Asked by: username_0 on 2018-07-03)
  
  I've set up a new CiviCRM install on a new Drupal install and I'm trying to configure Cron using the instructions at https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/.
  I'm a complete newbie at both CiviCRM and Drupal, and both the cv and Drush methods look like they need extra tools installed, so I've gone with the cli.php method.
  I'm logged in to my host using SSH and using the command from the manual (obviously completed with the paths, domain, and credentials for my site):
  $ /path/to/php /path/to/civcrm/bin/cli.php \
    -s example.org \
    -u myusername \
    -p mypassword \
    -e Job \
    -a execute
  
  That returns a bunch of HTML, obviously designed to be shown in a browser not a terminal, in which the only recognisable error message is 'DB Error: connect failed'.
  Can anyone tell me what I'm doing wrong?
  Edit: OK, so I've tested getting the password wrong and that gets the same error, so I guess it's possible that I have a credentials problem of some kind. But I'm using the username and password of a Drupal administrator user that works just fine logging into the CMS via a browser.
  The only other thing I can think is that I think my file installation and my database are on different servers. But I filled in all those details when installing Drupal/CiviCRM and I don't see any errors in the GUI. Do I need to manually edit a script somewhere?
  Further Edit: Still without joy, I gave up on the cli.php method and tried the HTTP method documented on the same page above. Trying to open the following URL in a browser results in exactly the same error, though obviously presented properly instead of raw HTML.
  http:///sites/all/modules/civicrm/bin/cron.php?name=&pass=&key=
  
  
  Can that narrow down the source of the problem at all?
  Yet Further Edit: Looking in the logs I see the following:
  [code] => -24
  [message] => DB Error: connect failed
  [mode] => 16
  [debug_info] =>  [nativecode=Access denied for user ''@'' (using password: YES)]
  [type] => DB_Error
  [user_info] =>  [nativecode=Access denied for user ''@'' (using password: YES)]
  [to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::handle prefix="" info=" [nativecode=Access denied for user ''@'' (using password: YES)]"]
  
  I was surprised to see that it seems to be trying to connect with the user I had set up for the Drupal database, rather than the user for the CiviCRM database. That user originally only had Select access to the CiviCRM database. I've now given both users full access to both databases (which instinctively feels like a non-ideal setup?), but I'm still getting the same error.
  
  **Tags:** drupal, installation, cron, scheduled-job
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2018-07-10. Score: 2 | Accepted answer
  
  And after all that, it looks like it was a password error after all, just not the password I thought.
  
  cli.php is retrieving the Drupal MySQL username and password from CIVICRM\_UF\_DSN in civicrm.settings.php as Jon G suggested. The instructions in that file say 'If any of these contain a single quote or backslash, escape those characters with a backslash: \' and \, respectively.' My password contained a double quote, and whichever script had generated that file put a backslash before the double quote: \". Taking the slash out seems to let the command run fine.
  
  > **Comments:**
  > **username_1**: This sounds like a bug to me. Follow these steps to report it: https://civicrm.org/bug-reporting. Thanks!  
  
  ---
  
  ### Answer by username_2 on 2018-07-06. Score: 3
  
  First, you can view the error with greater detail if you enable "Debug and Backtrace", or view the CiviCRM log. The [troubleshooting documentation](https://docs.civicrm.org/sysadmin/en/latest/troubleshooting/) will tell you how to do both.
  
  Second, I would assume that "connect failed" is a MySQL error. Is it possible that you have two `civicrm.settings.php` files in your path, one with the wrong MySQL password?
  
  Finally - yes, `drush` and `cv` are additional tools to install. However, if you're administering Drupal/CiviCRM through SSH, these tools are amazing timesavers. Configuring cron with cv or drush is 10 times easier than what you're doing here, even if you factor in the overhead of installing drush or cv. Drush in particular will give you a number of other command-line superpowers - you'll be glad you installed it.
  
  > **Comments:**
  > **username_0**: Sorry, first chance to test things after the weekend. Thank you.  As far as I can see I only have one civicrm.settings.php file, in /<drupalroot>/sites/default. I do have a settings.php and a default.settings.php, if that makes any difference?  
  > **username_0**: Sorry, not getting my head around this comment system exactly. I've added what I found in the logs to the original post. Will go an have another look at Drush, but I was finding the documentation somewhat unhelpful!  
  
  ---
  
  ### Answer by username_3 on 2018-07-06. Score: 2
  
  I was also going to add that there are alternatives, e.g. CiviHosting offer this method which can be done via the hosting control panel <https://civihosting.com/blog/how-to-make-a-cron-job-for-civicrm/>
  
  And then you can also use an extension to use the Drupal cron to trigger the CiviCRM cron:
  <https://civicrm.org/extensions/civicrm-cron>
  
  Not quite as satisfying as figuring it out via the SSH route but if you've tried several times and to no avail, this might just get it going for you.
  
  > **Comments:**
  > **username_0**: Thanks. Both the options in that CiviHosting document seem to require having either the CLI or HTTP method working to start with though, which are both failing for me. Are there instructions anywhere on how to install that CiviCRM Cron module? 'Cause I'm getting an error using the standard Drupal Install new module link.  
  > **username_3**: @username_0 what's the error message when you're installing the module? Have you tried to upload and decompress it directly into the File Manager?  
  > **username_3**: Looking at your logs, just to clarify, does drupal_database_user refer to the MySQL user or a user in the Drupal frontend? It's the latter that you need to use to run the cron.  
  > **username_0**: The username that's coming back denied in the error message is the MySQL user. But the username I'm submitting through either cli or chron.php is a Drupal user I created exclusively for this purpose.  
  > **username_0**: Ah ha! I've uploaded the uncompressed CiviCRM Cron directly into `/<drupalroot>/sites/all/modules` and it seems to be working! I didn't notice at first because the configuration link didn't seem to appear until I refreshed the modules list after enabling it. The video linked on the extension page suggests that it's not really suitable for production sites, but it's five years old. Is that still true? Sorry, like I said, complete newbie!  
  > **username_3**: Hurrah! Glad it's all come together - all I know is that a CiviCRM implementer near me currently uses it for live sites. You'll just have to use it and see - if anything isn't working properly, disable the cron in case that's causing issues.  
  
  ---
  
  