Answers.Body: <p>I'm not sure I've got a good answer for you here.</p>
  
  <p>Craft 2.x uses <a href="http://guzzle.readthedocs.org/en/latest/" rel="nofollow">Guzzle</a> 3.x for all of its outbound communications, so I'm not sure if it would be respecting <code>stream_context_set_default</code> at all.</p>
  
  <p>If I recall, the last time someone brought this up, we looked into it and decided we needed to update to the latest Guzzle (5.x) to properly support it (they release quickly).</p>
  
  <p>Unfortunately both Guzzle 4.x and 5.x introduced breaking changes to Craft.  So it'll have to be Craft 3.x before we add outbound proxy connection configuration options to Craft.</p>
  
  <p>The only workarounds I can think of until then are to whitelist the IP address(es) of the Craft install to allow direct outbound access if that's possible.  If you can't do that, then maybe you can just get away with manual updates and let license checking silently fail.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-16T19:32:47.380Z
Answers.Text: I updated my question following your answer. Looks like proxy is doable in Guzzle 3.x. I guess that would require editing the core, but until Craft 3 is released maybe that's the best option. If it is doable at all. What do you think ?
Answers.UserDisplayName: SierraRomeo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-16T19:41:29.633Z
Answers.Text: Just keep in mind that an auto-update could and a manual update would overwrite any core file changes. Also, Craft has dependencies (SimplePie for feeds, S3, Rackspace, etc.) that  make their own external calls that don't go through our Guzzle dependency.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-16T20:04:08.400Z
Answers.Text: Yes i am well aware of that. I will run some tests on Monday to see which files may be impacted in relation with an auto-update. I take note that proxy configuration is on your todo list for Craft 3.
Answers.UserDisplayName: SierraRomeo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-16T18:17:05.377Z
Answers.LastActivityDate: 2015-01-16T18:17:05.377Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a Craft application in an intranet behind a proxy.
  I'm struggling to find a way of configuring the application so it can access the internet via the proxy, in particular for the auto updating and license check.</p>
  
  <p>I tried using PHP's stream_context_set_default() but cannot get it to work in the admin section. Here's what i did so far:</p>
  
  <p>I created a connect.php file in my public folder just to check if my script works.
  It does as i can get the headers for any site.</p>
  
  <pre><code>$PROXY_HOST = "url.to.my.proxy";
  $PROXY_PORT = "8080";
  $PROXY_USER = "username";
  $PROXY_PASS = "password";
  
  $auth = base64_encode("$PROXY_USER:$PROXY_PASS");
  stream_context_set_default(
    array(
      'http' =&gt; array(
        'proxy' =&gt; "tcp://$PROXY_HOST:$PROXY_PORT",
        'request_fulluri' =&gt; true,
        'header' =&gt; "Proxy-Authorization: Basic $auth"
      )
    )
  );
  
  $url = "https://elliott.buildwithcraft.com/actions/elliott/app/ping";
  
  print_r( get_headers($url) );
  </code></pre>
  
  <p>From there, i'm stuck. I have no idea what to do next to try and inject that into the auto updating part of Craft. I know it's bad to mess with the core, and don't want to, but i have no idea where to go from here.</p>
  
  <p>Anyone been in a similar situation ?<br>
  Am i missing something obvious where all of this wouldn't be needed ? (hope so)</p>
  
  <hr>
  
  <p>Following @BradBell answer i searched for Guzzle information and found this in the <a href="https://github.com/guzzle/guzzle3/blob/master/docs/http-client/request.rst#request-options" rel="nofollow">documentation for Guzzle 3.x</a>:</p>
  
  <blockquote>
    <p>Requests options can be specified when creating a request or in the request.options parameter of a client. These options can control various aspects of a request including: headers to send, query string data, where the response should be downloaded, proxies, auth, etc.</p>
  </blockquote>
  
  <pre><code>$request = $client-&gt;get($url, $headers, array('proxy' =&gt; 'http://proxy.com'));
  </code></pre>
  
  <p>Maybe this can be put to some use in the current Craft install?<br>
  If so, some guidance will be greatly appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-21T17:38:06.560Z
Comments.Text: Wow this is nice but can you figure out how to do it on a school chromebook? :)
Comments.UserDisplayName: Claire Staples
Tags: <config><auto-updates><updating>
Title: How to configure Craft to use a Proxy?
ThreadText: # How to configure Craft to use a Proxy?
  
  (Asked by: username_0 on 2015-01-16)
  
  I have a Craft application in an intranet behind a proxy.
  I'm struggling to find a way of configuring the application so it can access the internet via the proxy, in particular for the auto updating and license check.
  
  I tried using PHP's stream\_context\_set\_default() but cannot get it to work in the admin section. Here's what i did so far:
  
  I created a connect.php file in my public folder just to check if my script works.
  It does as i can get the headers for any site.
  
  ```
  $PROXY_HOST = "url.to.my.proxy";
  $PROXY_PORT = "8080";
  $PROXY_USER = "username";
  $PROXY_PASS = "password";
  
  $auth = base64_encode("$PROXY_USER:$PROXY_PASS");
  stream_context_set_default(
    array(
      'http' => array(
        'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
        'request_fulluri' => true,
        'header' => "Proxy-Authorization: Basic $auth"
      )
    )
  );
  
  $url = "https://elliott.buildwithcraft.com/actions/elliott/app/ping";
  
  print_r( get_headers($url) );
  
  ```
  
  From there, i'm stuck. I have no idea what to do next to try and inject that into the auto updating part of Craft. I know it's bad to mess with the core, and don't want to, but i have no idea where to go from here.
  
  Anyone been in a similar situation ?  
  Am i missing something obvious where all of this wouldn't be needed ? (hope so)
  
  ---
  
  Following @username_2 answer i searched for Guzzle information and found this in the [documentation for Guzzle 3.x](https://github.com/guzzle/guzzle3/blob/master/docs/http-client/request.rst#request-options):
  
  > Requests options can be specified when creating a request or in the request.options parameter of a client. These options can control various aspects of a request including: headers to send, query string data, where the response should be downloaded, proxies, auth, etc.
  
  ```
  $request = $client->get($url, $headers, array('proxy' => 'http://proxy.com'));
  
  ```
  
  Maybe this can be put to some use in the current Craft install?  
  If so, some guidance will be greatly appreciated.
  
  **Tags:** config, auto-updates, updating
  
  > **Comments:**
  > **username_1**: Wow this is nice but can you figure out how to do it on a school chromebook? :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-01-16. Score: 1
  
  I'm not sure I've got a good answer for you here.
  
  Craft 2.x uses [Guzzle](http://guzzle.readthedocs.org/en/latest/) 3.x for all of its outbound communications, so I'm not sure if it would be respecting `stream_context_set_default` at all.
  
  If I recall, the last time someone brought this up, we looked into it and decided we needed to update to the latest Guzzle (5.x) to properly support it (they release quickly).
  
  Unfortunately both Guzzle 4.x and 5.x introduced breaking changes to Craft. So it'll have to be Craft 3.x before we add outbound proxy connection configuration options to Craft.
  
  The only workarounds I can think of until then are to whitelist the IP address(es) of the Craft install to allow direct outbound access if that's possible. If you can't do that, then maybe you can just get away with manual updates and let license checking silently fail.
  
  > **Comments:**
  > **username_0**: I updated my question following your answer. Looks like proxy is doable in Guzzle 3.x. I guess that would require editing the core, but until Craft 3 is released maybe that's the best option. If it is doable at all. What do you think ?  
  > **username_2**: Just keep in mind that an auto-update could and a manual update would overwrite any core file changes. Also, Craft has dependencies (SimplePie for feeds, S3, Rackspace, etc.) that  make their own external calls that don't go through our Guzzle dependency.  
  > **username_0**: Yes i am well aware of that. I will run some tests on Monday to see which files may be impacted in relation with an auto-update. I take note that proxy configuration is on your todo list for Craft 3.  
  
  ---
  
  