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

Laravel项目克隆到VSCode及本地运行问题求助:WSL环境下Composer配置失败、PHP命令报错,求简便克隆方案

Hey there! Let's work through this step by step to get your Laravel project running smoothly, and also cover some simpler alternatives if you're stuck on the WSL/Composer setup headaches.

First: Fix the WSL PHP/Composer Issues

The most likely culprit is that your WSL environment doesn't have PHP (with required extensions) or Composer properly set up. Let's fix that:

  • Verify & Install PHP in WSL
    Open your WSL terminal and run php -v. If you get an error, install PHP and the extensions Laravel needs (for Ubuntu/Debian-based WSL):

    sudo apt update && sudo apt install php-cli php-mbstring php-xml php-zip php-mysql
    

    Double-check with php -v to confirm it's installed successfully.

  • Install Composer Globally
    Run these commands in WSL to set up Composer the official way:

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    sudo mv composer.phar /usr/local/bin/composer
    

    Test it with composer -v—you should see version info pop up if it worked.

  • Clone & Configure the Project
    Clone your project directly in WSL to avoid cross-filesystem glitches:

    git clone <your-project-repo-url>
    cd <your-project-folder>
    

    Run composer install to install dependencies. If you hit permission errors, fix them with:

    sudo chmod -R 755 storage bootstrap/cache
    sudo chown -R $USER:$USER .
    

    Finish setup with these final steps:

    cp .env.example .env
    php artisan key:generate
    php artisan serve
    

    Now open the project folder in VSCode via Remote-WSL, and you're ready to develop.

Simpler Alternatives to Clone & Run Laravel

If WSL feels too fussy, try these low-config options:

  • Local Windows Setup (No WSL)

    1. Install XAMPP or WAMP—pick one that includes a PHP version matching your Laravel project's requirements (e.g., Laravel 10 needs PHP 8.1+).
    2. Download and install the official Windows Composer installer (it auto-detects your PHP path automatically).
    3. Open Windows Terminal, clone your project, then run the same setup commands: composer install, cp .env.example .env, php artisan key:generate, php artisan serve.
  • Laravel Sail (Docker-Based)
    This is Laravel's official zero-config way to run projects using Docker:

    1. Install Docker Desktop (enable WSL integration if you prefer using WSL, or just use the native Windows version).
    2. Clone your project, then in the project folder, run:
      # If you have Composer locally
      composer require laravel/sail --dev
      # If no local Composer, use this Docker command instead
      docker run --rm -v "$(pwd):/opt" -w /opt laravelsail/php82-composer:latest require laravel/sail --dev
      
    3. Generate Sail's config: php artisan sail:install (select services like MySQL when prompted).
    4. Start the containers: ./vendor/bin/sail up—your project will be available at http://localhost.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 22:52:39