You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lumen新手执行Composer更新时遇getaddrinfo网络错误,求解决方案

Fixing "php_network_getaddresses: getaddrinfo failed" in Composer for Lumen

Hey there! I’ve seen this error pop up all the time with Composer—it almost always boils down to a network or DNS issue that’s stopping Composer from reaching package repositories like Packagist. Let’s walk through the fixes step by step:

1. Verify Network & DNS Resolution

First, let’s confirm if your system can even reach the package repository. Run this command in your terminal:

ping packagist.org

If you get "Name or service not known" here too, your DNS isn’t resolving Packagist’s domain. Here’s how to fix that:

  • Switch to a public DNS: Use services like Google’s 8.8.8.8 or China’s 114.114.114.114.
    • On Linux: Edit /etc/resolv.conf and add nameserver 8.8.8.8
    • On Windows: Go to Network Settings → Change adapter options → Right-click your network → Properties → IPv4 → Use the following DNS server addresses
    • On Mac: System Preferences → Network → Advanced → DNS → Add the DNS server
  • Flush your DNS cache:
    • Linux: sudo systemctl restart systemd-resolved (or sudo service nscd restart depending on your distro)
    • Windows: ipconfig /flushdns
    • Mac: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

2. Switch to a Composer Mirror (Great for Regions with Slow Packagist Access)

If DNS is working but Packagist is slow or unreachable, swap to a faster mirror. For example, the Alibaba Cloud mirror is reliable for many regions:

# Set globally for all projects
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# Or just for your current Lumen project (remove the -g flag)
composer config repo.packagist composer https://mirrors.aliyun.com/composer/

3. Check Proxy Settings (If You’re Behind a Firewall/Proxy)

If you’re on a work or school network with a proxy, Composer might not be configured to use it.

  • Check your current proxy config:
    composer config -g --list | grep proxy
    
  • Set the proxy if needed:
    composer config -g http.proxy http://your-proxy-address:port
    composer config -g https.proxy https://your-proxy-address:port
    
  • If you don’t need a proxy anymore, clear the settings:
    composer config -g --unset http.proxy
    composer config -g --unset https.proxy
    

4. Retry with Fresh Cache & Updated Composer

After fixing the network/DNS/proxy issues, run these commands to reset and try again:

composer clear-cache
composer self-update # Make sure you’re on the latest Composer version
composer update --verbose # Verbose mode helps spot any lingering issues

Most of the time, one of these steps will get Composer working again. Start with the DNS check—it’s the most common culprit!

内容的提问来源于stack exchange,提问作者DINA TAKLIT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:08:26