Windows环境下通过Composer安装Laravel项目报错求助
Hey Martin, let's break down what's going wrong here and fix it step by step!
What's Causing the Errors?
You've run into two separate issues, both tied to misusing the Composer global directory:
- Laravel Installer Permission Error: You manually created the
C:\Users\marti\AppData\Roaming\Composer\vendor\bindirectory, but Windows restricts write permissions for manually created folders in theAppDatasystem directory. Composer can't write the Laravel Installer files here. create-projectConfig File Error: You tried to initialize a Laravel project directly insideC:\Users\marti\AppData\Roaming\Composer\vendor\bin—this directory is for global Composer tools (like the Laravel Installer), not your actual Laravel projects. Composer expects a valid project directory with acomposer.jsonfile, which doesn't exist here.
Step 1: Fix the Composer Global Bin Directory
Let's reset the global bin directory to let Composer handle it properly:
- First, delete the manually created
C:\Users\marti\AppData\Roaming\Composer\vendor\binfolder. Composer will automatically generate this folder with correct permissions later. - Open Command Prompt as an administrator, then run this command to install the Laravel Installer globally:
Composer will now create thecomposer global require laravel/installervendor\bindirectory automatically and set the right permissions for it. - Double-check that your Windows
Pathenvironment variable still includesC:\Users\marti\AppData\Roaming\Composer\vendor\bin(you already set this earlier, so this is just a quick verification step).
Step 2: Create Your Laravel Project Correctly
You need to create your project in a user-controlled folder (not the Composer system directory). Here's how to do it with both methods:
Using Laravel Installer
Run this command to create a project in your desired location (replace C:\Projects\my-laravel-app with your actual preferred path):
laravel new C:\Projects\my-laravel-app
Or if you're already in your projects folder via Command Prompt, just run:
laravel new my-laravel-app
Using composer create-project
Same idea—point the command to a user folder:
composer create-project laravel/laravel C:\Projects\my-laravel-app
Or from your projects directory:
composer create-project laravel/laravel my-laravel-app
That should get your Laravel project up and running without permission or config errors!
内容的提问来源于stack exchange,提问作者Martin Kiprotich

