社内LANなど、外部へアクセスするときにProxyサーバが必要な環境で、composerを使用すると下記のエラーが出てパッケージのダウンロードに失敗する場合があります。
> composer require monolog/monolog
file could not be downloaded: failed to open stream: Cannot connect to HTTPS server through proxy
composer diag
コマンドを実行して診断を行っても、下記のようにエラーになります。
> composer diag
Checking platform settings: OK
Checking http connectivity: OK
Checking HTTP proxy: OK
Checking HTTP proxy support for request_fulluri: OK
Checking HTTPS proxy support for request_fulluri: FAIL
Unable to assert the situation, maybe github is down (The "https://api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)
failed to open stream: Cannot connect to HTTPS server through proxy)
Checking composer.json: FAIL
...
このような場合は、PCの環境変数を設定してみてください。
Unix環境の場合
UnixやMacを使用している場合は、下記の環境変数を設定します。
~/.bashrcなどの、シェル起動時に読み込まれる設定に付け加えておくと、毎回設定せずに済むので便利です。
export HTTP_PROXY_REQUEST_FULLURI=0
export HTTPS_PROXY_REQUEST_FULLURI=0
Windows環境の場合
Window環境の場合、システム環境変数のhttp_proxyとhttps_proxyを見ているので、composerコマンドの実行前に下記のコマンドを入力すればよいです。
set http_proxy="servername.co.jp:8080"
set https_proxy="servername.co.jp:8080"
こちらもおススメ