|
| 1 | +# How to use Composer behind a proxy |
| 2 | + |
| 3 | +Composer, like many other tools, uses environment variables to control the use of a proxy server and |
| 4 | +supports: |
| 5 | + |
| 6 | +- `http_proxy` - the proxy to use for HTTP requests |
| 7 | +- `https_proxy` - the proxy to use for HTTPS requests |
| 8 | +- `CGI_HTTP_PROXY` - the proxy to use for HTTP requests in a non-CLI context |
| 9 | +- `no_proxy` - domains that do not require a proxy |
| 10 | + |
| 11 | +These named variables are a convention, rather than an official standard, and their evolution and |
| 12 | +usage across different operating systems and tools is complex. Composer prefers the use of lowercase |
| 13 | +names, but accepts uppercase names where appropriate. |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Composer requires specific environment variables for HTTP and HTTPS requests. For example: |
| 18 | + |
| 19 | +``` |
| 20 | +http_proxy=http://proxy.com:80 |
| 21 | +https_proxy=http://proxy.com:80 |
| 22 | +``` |
| 23 | + |
| 24 | +Uppercase names can also be used. |
| 25 | + |
| 26 | +### Non-CLI usage |
| 27 | + |
| 28 | +Composer does not look for `http_proxy` or `HTTP_PROXY` in a non-CLI context. If you are running it |
| 29 | +this way (i.e. integration into a CMS or similar use case) you must use `CGI_HTTP_PROXY` for HTTP |
| 30 | +requests: |
| 31 | + |
| 32 | +``` |
| 33 | +CGI_HTTP_PROXY=http://proxy.com:80 |
| 34 | +https_proxy=http://proxy.com:80 |
| 35 | +
|
| 36 | +# cgi_http_proxy can also be used |
| 37 | +``` |
| 38 | + |
| 39 | +> **Note:** CGI_HTTP_PROXY was introduced by Perl in 2001 to prevent request header manipulation and |
| 40 | +was popularized in 2016 when this vulnerability was widely reported: https://httpoxy.org |
| 41 | + |
| 42 | +## Syntax |
| 43 | + |
| 44 | +Use `scheme://host:port` as in the examples above. Although a missing scheme defaults to http and a |
| 45 | +missing port defaults to 80/443 for http/https schemes, other tools might require these values. |
| 46 | + |
| 47 | +The host can be specified as an IP address using dotted quad notation for IPv4, or enclosed in |
| 48 | +square brackets for IPv6. |
| 49 | + |
| 50 | +### Authorization |
| 51 | + |
| 52 | +Composer supports Basic authorization, using the `scheme://user:pass@host:port` syntax. Reserved url |
| 53 | +characters in either the user name or password must be percent-encoded. For example: |
| 54 | + |
| 55 | +``` |
| 56 | +user: me@company |
| 57 | +pass: p@ssw$rd |
| 58 | +proxy: http://proxy.com:80 |
| 59 | +
|
| 60 | +# percent-encoded authorization |
| 61 | +me%40company:p%40ssw%24rd |
| 62 | +
|
| 63 | +scheme://me%40company:p%40ssw%24rd@proxy.com:80 |
| 64 | +``` |
| 65 | + |
| 66 | +> **Note:** The user name and password components must be percent-encoded individually and then |
| 67 | +combined with the colon separator. The user name cannot contain a colon (even if percent-encoded), |
| 68 | +because the proxy will split the components on the first colon it finds. |
| 69 | + |
| 70 | +## HTTPS proxy servers |
| 71 | + |
| 72 | +Composer supports HTTPS proxy servers, where HTTPS is the scheme used to connect to the proxy, but |
| 73 | +only from PHP 7.3 with curl version 7.52.0 and above. |
| 74 | + |
| 75 | +``` |
| 76 | +http_proxy=https://proxy.com:443 |
| 77 | +https_proxy=https://proxy.com:443 |
| 78 | +``` |
| 79 | + |
| 80 | +## Bypassing the proxy for specific domains |
| 81 | + |
| 82 | +Use the `no_proxy` (or `NO_PROXY`) environment variable to set a comma-separated list of domains |
| 83 | +that the proxy should **not** be used for. |
| 84 | + |
| 85 | +``` |
| 86 | +no_proxy=example.com |
| 87 | +# Bypasses the proxy for example.com and its sub-domains |
| 88 | +
|
| 89 | +no_proxy=www.example.com |
| 90 | +# Bypasses the proxy for www.example.com and its sub-domains, but not for example.com |
| 91 | +``` |
| 92 | + |
| 93 | +A domain can be restricted to a particular port (e.g. `:80`) and can also be specified as an IP |
| 94 | +address or an IP address block in CIDR notation. |
| 95 | + |
| 96 | +IPv6 addresses do not need to be enclosed in square brackets, like they are for |
| 97 | +http_proxy/https_proxy values, although this format is accepted. |
| 98 | + |
| 99 | +Setting the value to `*` will bypass the proxy for all requests. |
| 100 | + |
| 101 | +> **Note:** A leading dot in the domain name has no significance and is removed prior to processing. |
| 102 | +
|
| 103 | +## Deprecated environment variables |
| 104 | + |
| 105 | +Composer originally provided `HTTP_PROXY_REQUEST_FULLURI` and `HTTPS_PROXY_REQUEST_FULLURI` to help |
| 106 | +mitigate issues with misbehaving proxies. These are no longer required or used. |
| 107 | + |
| 108 | +## Requirement changes |
| 109 | + |
| 110 | +Composer <2.8 used `http_proxy` for both HTTP and HTTPS requests if `https_proxy` was not set, |
| 111 | +but as of Composer 2.8.0 it requires [scheme-specific](#usage) environment variables. |
| 112 | + |
| 113 | +The reason for this change is to align Composer with current practice across other popular tools. To help |
| 114 | +with the transition, as of Composer 2.7.3 the original behaviour remains but a warning message is |
| 115 | +shown instructing the user to add an `https_proxy` environment variable. |
| 116 | + |
| 117 | +To prevent the original behaviour during the transition period, set an empty environment variable |
| 118 | +(`https_proxy=`). |
0 commit comments