在 CentOS 系統中使用 Composer 時,如果需要通過代理服務器訪問互聯網,可以通過以下幾種方法配置代理:
臨時設置代理(僅對當前終端會話有效):
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=https://proxy.example.com:8080
永久設置代理(對所有終端會話有效):
~/.bashrc
或 ~/.bash_profile
文件,添加以下行:export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=https://proxy.example.com:8080
source ~/.bashrc
~/.composer/config.json
:composer config -g http-proxy http://proxy.example.com:8080
composer config -g https-proxy https://proxy.example.com:8080
--proxy
參數在執行 Composer 命令時,可以直接通過 --proxy
參數指定代理:
composer require vendor/package --proxy=http://proxy.example.com:8080
auth.json
文件如果你需要代理服務器進行身份驗證,可以在 ~/.composer/auth.json
文件中配置代理認證信息:
{
"http-basic": {
"proxy.example.com:8080": {
"username": "your-username",
"password": "your-password"
}
}
}
你可以通過以下命令驗證代理配置是否生效:
composer config -g http-proxy
composer config -g https-proxy
如果配置正確,你應該能看到設置的代理地址。
通過以上幾種方法,你可以在 CentOS 系統中成功配置 Composer 使用代理服務器。選擇適合你需求的方法進行配置即可。