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

Windows环境下Laravel安装与Composer问题:无法创建新项目求助

Hey there, let's tackle this Laravel project creation issue on Windows step by step—no need to stress, we'll get this sorted!

解决Windows下Laravel项目创建失败(Composer相关)的问题

第一步:先确认Composer本身是否正常工作

First things first, let's rule out issues with Composer itself. Open Command Prompt (CMD) or PowerShell and run:

composer --version

If you get an error, Composer isn't set up properly:

  • Check environment variables: Right-click "This PC" → Properties → Advanced System Settings → Environment Variables. Look for Composer's path (usually C:\ProgramData\ComposerSetup\bin) in the system Path variable.
  • If it's missing, reinstall Composer and make sure to check the "Add PHP to PATH" option during installation.

第二步:排查网络连接问题

Composer relies on Packagist to pull dependencies, and network glitches are a common culprit:

  • Test connectivity to Packagist first:
ping packagist.org

If you get high packet loss or no response, switch to a domestic mirror:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

To switch back later, run:

composer config -g --unset repos.packagist
  • Also, try turning off any VPN or proxy—they can interfere with Composer's requests.

第三步: Try two ways to create a Laravel project

Sometimes the Laravel Installer acts up, so let's try both methods:

Method 1: Use the Laravel Installer (if installed)

First verify the installer works:

laravel --version

If it's missing or outdated, reinstall it:

composer global require laravel/installer

Then create your project:

laravel new your-project-name

Method 2: Directly use Composer's create-project command

This method is more reliable if the installer fails:

composer create-project laravel/laravel your-project-name

You can also specify a version (e.g., Laravel 10):

composer create-project laravel/laravel:^10.0 your-project-name

第四步: Fix permission issues

Insufficient permissions on Windows often block project creation:

  • Right-click CMD/PowerShell and select "Run as administrator" before executing the creation command.
  • Check folder permissions for your project directory (e.g., D:\projects): Right-click the folder → Properties → Security → Edit, then grant your user account "Full Control" permissions.

第五步: Clear Composer's cache

Corrupted cache can cause unexpected errors. Run:

composer clear-cache

Then try creating the project again.

第六步: Verify PHP version and required extensions

Laravel has minimum PHP version requirements (e.g., Laravel 11 needs PHP 8.2+). Check your PHP version:

php --version

Also, make sure these extensions are enabled in your php.ini file (remove the leading semicolon if present):

  • extension=openssl
  • extension=pdo_mysql
  • extension=mbstring
  • extension=fileinfo
  • extension=gd
    Restart your command line tool after modifying php.ini, then retry the project creation.

If you still hit a wall, share the exact error message you're getting—that'll help pinpoint the problem faster!

内容的提问来源于stack exchange,提问作者arpit Pathak

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:20:31