在 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 使用代理服务器。选择适合你需求的方法进行配置即可。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:centos composer命令大全