Answers.Body: <p>Turns out this site was long ago upgraded from an older version that lacked <code>global $civicrm_settings</code> variable definition as called for in <a href="https://github.com/civicrm/civicrm-core/commit/f553d1eac3d3bd329fd85d0a2abf7b3acf2a7023#diff-6f64563f7e1018b992faf7184464d74f33fc44e0e3bf4371c6056ff3a62b39adL31" rel="nofollow noreferrer">this (5-year-old) commit in civicrm.settings.php.tpl</a>.</p>
  <p>Simply adding that variable definition cleared up the problem immediately. (Naturally there were other important things to change in civicrm.settings.php, so of course if you have this problem, you've probably got others.)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-10T18:51:43.910Z
Answers.LastActivityDate: 2022-05-10T18:51:43.910Z
Answers.UserDisplayName: TwoMice
Body: <p><strong>Question:</strong> What could be causing the <code>ext_repo_url</code> setting value to be empty when running in the browser, though it appears to be correct when running in <code>cv</code>?</p>
  <p>Under civicrm 5.35.2, if I visit the Extensions page, I see this message:</p>
  <blockquote>
  <p>Extension download error<br />
  The CiviCRM public extensions directory at could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on CiviCRM forum.</p>
  </blockquote>
  <p>Notice that it says &quot;extensions directory <em>at could</em> not&quot;, implying an empty value for the repo URL.</p>
  <p>Things seem to work normally using <code>cv</code>:</p>
  <ul>
  <li>At the command line I run <code>cv api Extension.getremote</code>, I get a full json array of remote extensions.</li>
  <li>From the command line, the setting has what appears to be a correct value.</li>
  </ul>
  <pre><code>cv api setting.get | grep -i ext_repo_url  
  &quot;ext_repo_url&quot;: &quot;https://civicrm.org/extdir/ver={ver}|cms={uf}&quot;,
  </code></pre>
  <ul>
  <li>I also tried a script with <code>cv scr</code>, and get what looks like correct output, like so:</li>
  </ul>
  <pre><code>$ cat /tmp/a.php
  &lt;?php
  $a = CRM_Extension_System::singleton()-&gt;getBrowser()-&gt;getRepositoryUrl();
  var_dump($a);
  $ cv scr /tmp/a.php
  string(51) &quot;https://civicrm.org/extdir/ver=5.35.2|cms=WordPress&quot;
  </code></pre>
  <p>But for content called from the browser, the repo setting appears to be empty. To test, I added this code to an existing extension:</p>
  <pre><code>function activityical_civicrm_pageRun(&amp;$page) {
    $page_name = $page-&gt;getVar('_name');
  $repo = CRM_Extension_System::singleton()-&gt;getBrowser()-&gt;getRepositoryUrl();
  echo &quot;&lt;!-- page_name: $page_name --&gt;\n&quot;;
  echo &quot;&lt;!-- repo_url: $repo  --&gt;\n&quot;;
  </code></pre>
  <p>And then I view the page source at <a href="https://REDACTED.example.org/wp-admin/admin.php?page=CiviCRM&amp;q=civicrm%2Fadmin%2Fextensions&amp;reset=1" rel="nofollow noreferrer">https://REDACTED.example.org/wp-admin/admin.php?page=CiviCRM&amp;q=civicrm%2Fadmin%2Fextensions&amp;reset=1</a> , which says:</p>
  <pre><code>&lt;!-- page_name: CRM_Admin_Page_Extensions --&gt;
  &lt;!-- repo_url:  --&gt;
  &lt;!DOCTYPE html&gt;
  </code></pre>
  <p>Also tried:</p>
  <ul>
  <li><code>cv flush</code> and <code>wp cache flush</code> do not make any change in the above findings.</li>
  </ul>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-30T19:09:28.620Z
Comments.Text: Is this a multidomain setup?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-02T20:46:08.083Z
Comments.Text: Nope, just one domain on this server.
Comments.UserDisplayName: TwoMice
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-04T09:12:10.637Z
Comments.Text: Is memcache active?
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-04T20:53:03.113Z
Comments.Text: Aidan: nope, no memcache.
Comments.UserDisplayName: TwoMice
Tags: <extension><settings>
Title: "The CiviCRM public extensions directory at could not be contacted" -- why is my repo URL empty in the browser but not in `cv`?
ThreadText: # "The CiviCRM public extensions directory at could not be contacted" -- why is my repo URL empty in the browser but not in `cv`?
  
  (Asked by: username_0 on 2021-04-30)
  
  **Question:** What could be causing the `ext_repo_url` setting value to be empty when running in the browser, though it appears to be correct when running in `cv`?
  
  Under civicrm 5.35.2, if I visit the Extensions page, I see this message:
  
  > Extension download error  
  > The CiviCRM public extensions directory at could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on CiviCRM forum.
  
  Notice that it says "extensions directory *at could* not", implying an empty value for the repo URL.
  
  Things seem to work normally using `cv`:
  
  * At the command line I run `cv api Extension.getremote`, I get a full json array of remote extensions.
  * From the command line, the setting has what appears to be a correct value.
  
  ```
  cv api setting.get | grep -i ext_repo_url  
  "ext_repo_url": "https://civicrm.org/extdir/ver={ver}|cms={uf}",
  
  ```
  
  * I also tried a script with `cv scr`, and get what looks like correct output, like so:
  
  ```
  $ cat /tmp/a.php
  <?php
  $a = CRM_Extension_System::singleton()->getBrowser()->getRepositoryUrl();
  var_dump($a);
  $ cv scr /tmp/a.php
  string(51) "https://civicrm.org/extdir/ver=5.35.2|cms=WordPress"
  
  ```
  
  But for content called from the browser, the repo setting appears to be empty. To test, I added this code to an existing extension:
  
  ```
  function activityical_civicrm_pageRun(&$page) {
    $page_name = $page->getVar('_name');
  $repo = CRM_Extension_System::singleton()->getBrowser()->getRepositoryUrl();
  echo "<!-- page_name: $page_name -->\n";
  echo "<!-- repo_url: $repo  -->\n";
  
  ```
  
  And then I view the page source at <https://REDACTED.example.org/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fadmin%2Fextensions&reset=1> , which says:
  
  ```
  <!-- page_name: CRM_Admin_Page_Extensions -->
  <!-- repo_url:  -->
  <!DOCTYPE html>
  
  ```
  
  Also tried:
  
  * `cv flush` and `wp cache flush` do not make any change in the above findings.
  
  **Tags:** extension, settings
  
  > **Comments:**
  > **username_1**: Is this a multidomain setup?  
  > **username_0**: Nope, just one domain on this server.  
  > **username_2**: Is memcache active?  
  > **username_0**: username_2: nope, no memcache.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-05-10. Score: 2
  
  Turns out this site was long ago upgraded from an older version that lacked `global $civicrm_settings` variable definition as called for in [this (5-year-old) commit in civicrm.settings.php.tpl](https://github.com/civicrm/civicrm-core/commit/f553d1eac3d3bd329fd85d0a2abf7b3acf2a7023#diff-6f64563f7e1018b992faf7184464d74f33fc44e0e3bf4371c6056ff3a62b39adL31).
  
  Simply adding that variable definition cleared up the problem immediately. (Naturally there were other important things to change in civicrm.settings.php, so of course if you have this problem, you've probably got others.)
  
  
  ---
  
  