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

无法在本地系统安装Laravel,遇Composer主机解析错误

Hey there! Let's work through this Laravel installation issue you're facing with Composer. That error message clearly points to a network/DNS problem where your system can't resolve the packagist.org domain. Here's how to fix it step by step:

Fixing Composer's "getaddrinfo failed" Error When Installing Laravel

First, let's break down the problem: The [Composer\Downloader\TransportException] error you're seeing means your system can't find the server address for packagist.org—this is a classic DNS resolution failure. Let's tackle it with these solutions:

1. Verify Basic Network Connectivity

  • Try visiting packagist.org in your browser or running ping packagist.org in your terminal (Command Prompt for Windows, Terminal for Mac/Linux). If it says "host not found," your network can't reach the domain at all.
  • If you're on a restricted network (like work/school), check if the network blocks access to external package repositories.

2. Switch to a Public DNS Server

DNS issues are often the culprit. Swap your current DNS with a public one to see if that helps:

  • Windows: Go to Network Settings → Your active connection → Properties → IPv4 → Use the following DNS server addresses: Enter 8.8.8.8 (Google DNS) or 1.1.1.1 (Cloudflare DNS).
  • Mac: System Preferences → Network → Advanced → DNS → Click the "+" button to add 8.8.8.8 or 1.1.1.1.
  • Linux: Edit /etc/resolv.conf and add nameserver 8.8.8.8, then restart your network service (e.g., sudo systemctl restart network-manager).

3. Bypass HTTPS Temporarily (Emergency Fix)

Sometimes HTTPS certificate issues or proxy settings block access. You can tell Composer to use HTTP instead (note: this is not secure for long-term use, just for testing):

composer create-project laravel/laravel your-project-name --no-secure-http

The --no-secure-http flag disables HTTPS for Composer's requests to packagist.

4. Configure Proxy Settings (If Needed)

If you're behind a proxy server (common in corporate networks), set up Composer to use it:

# Set proxy for HTTP and HTTPS
composer config -g http.proxy http://your-proxy-ip:port
composer config -g https.proxy https://your-proxy-ip:port

# If you need to remove proxy settings later
composer config -g --unset http.proxy
composer config -g --unset https.proxy

5. Update Composer to the Latest Version

Old Composer versions might have network compatibility bugs. Update it first:

composer self-update

6. Manual Project Setup (Alternative)

If all else fails, you can set up Laravel manually:

  • Download the latest Laravel project zip from the official site, extract it to your desired folder.
  • Navigate to the project folder in your terminal and run composer install to install all dependencies.

内容的提问来源于stack exchange,提问作者Vibhash kumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:42:13